calculate inclined ellipse semi axes that is inscribed in a parallelogram at the mid points

151 Views Asked by At

I'm working on a function in c++ to find the semi-major-axis 'a' and semi-minor-axis 'b' of an inclined ellipse that is inscribed in a parallelogram ABCD, where AB is parallel to CD and BC is parallel to AD, and the ellipse is touching the middle points of each side of the parallelogram. Ellipse inscribed in parallelogram touching the mid points of it

The input parameters are :

  • Two points p1(x1,y1) and p2(x2,y2) that touches the perimeter of the ellipse at the mid points of segments AB for p1 and AD for p2.
  • The center of the ellipse p0(x0,y0).
  • The angle from the center (x0,y0) to the point (x1,y1) called B:[-Pi,Pi].
  • The angle from the center (x0,y0) to the point (x2,y2) called C:[-Pi,Pi].

So the function looks like this:

std::pair<double ,double> calculateEllipseSemiAxes(Point p0, Point p1, Point p2, double A, double B, double C) 
{
  double a; //semi-major axis
  double b, //semi-minor axis

  //find a and b ...

  return {a,b};
}

The inclined ellipse equations I've presented before doesn't work for me cause I want to be able to create the points for an arc of the ellipse from p1 to p2 so now I'm using these equations:

//parameters
auto angle       = ellipseParameters.angleBegin;
const auto x0    = ellipseParameters.center.x;
const auto y0    = ellipseParameters.center.y;
const auto ab    = ellipseParameters.a * ellipseParameters.b;
const auto asq   = ellipseParameters.a * ellipseParameters.a;
const auto bsq   = ellipseParameters.b * ellipseParameters.b;
auto inclination = ellipseParameters.inclinationAngle;

//variables
double totalAngle, cosAngle, sinAngle, rAngle;
cosAngle = std::cos(angle);
sinAngle = std::sin(angle);
totalAngle = angle + inclination;

//inclined ellipse equations
rAngle = ab / std::sqrt( asq * sinAngle * sinAngle + bsq * cosAngle * cosAngle );

 //results
 auto x = x0 + rAngle * std::cos(totalAngle); //for x coord
 auto y = y0 + rAngle * std::sin(totalAngle); //for y coord