function y = pyriform_egg ( B, L, w, x )

%*****************************************************************************80
%
%% pyriform_egg() returns the outline of a pyriform egg.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 June 2011
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Valeriy Narushin, Michael Romanov, Darren Griffin,
%    "Egg and math: introducing a universal formula for egg shape",
%    Annals of the New York Academy of Sciences,
%    Number 1505, pages 169-177, 23 August 2021.
%
%  Input:
%
%    real B, the maximum breadth of the egg (y direction);
%
%    real L, the maximum length of the egg (x direction).
%
%    real w: the x-distance between the location of the maximum
%    breadth and the midpoint of the egg's length (x=0).
%
%    real x(*): sample points between -L/2 and +L/2.
%
%  Output:
%
%    real y(*): the height of the egg at each x value.
%    The egg is assumed to be vertically symmetric, and 
%    rotationally symmetric about the x axis.
%
  t1 = ( L^2 - 4.0 * x.^2 ) * L;
  t2 = 2.0 * ( L - 2.0 * w ) * x.^2 ...
    + ( L^2 + 8.0 * L * w - 4.0 * w^2 ) * x ...
    + 2.0 * L * w^2 + L^2 * w + L^3;
  y = 0.5 * B * sqrt ( t1 ./ t2 );

  return
end

