# Region bounded by Ellipse and Line

I have an ellipse defined either as algebraic or geometric:

algebraic: ax^2 + bxy +cy^2 + dx +ey +f = 0

geometric: major Axis, minor Axis, x center, y center, rotation angle from horizontal

And I have a line that could be defined by two points (x1,y1) and (x2,y2)

These two objects would intersect each other: ## Question

How could I model the two objects, so that:

For an ELLIPSE, I could get -

1) Length of the line within the ellipse

2) Area of the yellow shaded region (i.e. smaller area)

## Attempt

Previously I was able to get the area for a rotated ellipsoid under a horizontal plane. But now I would like to arbitrarily model that line (instead of a plane).

Regards Caid

*UPDATE:

For a 3D ellipsoid:

Nvolume[p_, abc_] :=

I was able to obtain the volume bounded under a plane defined as: p = {Sin[k Degree], 0, Cos[k Degree]};

And then, the planar area:

Unfortunately, that's about what I have. I need to convert the plane into a line for a 2D case.

Also if possible, I would like to obtain general equations for both.

• This sounds like a question for math.stackexchange.com. Voting to migrate. Mar 26, 2015 at 9:51
• hmm actually i would like to model this in Mathematica Mar 26, 2015 at 9:56
• What have you tried so far? If you can show code it is more likely that people can show a solution.
– user9660
Mar 26, 2015 at 10:45
• Please add that bit of info to the question as well, then. Mar 26, 2015 at 12:12
• I have added the code which I was using previously, but only for the case of a 3D ellipsoid. Would like to be able to model a 2D case and obtain the general equations. Mar 27, 2015 at 2:38

I would suggest to use the parametric form of a centered, rotated ellipse

{a Cos[t] Cos[Theta] - b Sin[t] Sin[Theta], a Cos[t] Sin[Theta] + b Sin[t] Cos[Theta]}


with a,b as the semimajor and semiminor axis, Theta as the rotation angle of the ellipse (0 for an axis oriented ellipse).

The trick is to rotate and center your problem into a configuration where your ellipse is centered and your line is horizontal.

If you want your ellipse in centered orientation, then you need to rotate the line about this center and use its parametric version first translated by {-xe,-ye} and then rotated by phi which is (refer to Link):

{u Cos[phi]+v Sin[phi]-xe,−u Sin[phi]+v Cos[phi]-ye}


Entering this into the original line equation y=k x + d, solving for y and using the rotation angle -ArcTan[k] yields a horizontal line

Solve[k (u Cos[t] + v Sin[t] - xe) + d - ye == -u Sin[t] +
v Cos[t], v][[1, 1]] /. {u -> x, v -> y, t -> -ArcTan[k]} // Simplify


with

yl=(d - k xe - ye)/Sqrt[1 + k^2]


as the y-coordinate independent of x as expected.

The rotation angle is simply the negative of your angle phi between your line and the x-axis which is

phi=ArcTan[x2 - x1, y2 - y1]=ArcTan[k]


thus yielding the new parametric form of the Ellipse as

{a Cos[t] Cos[Theta-phi] - b Sin[t] Sin[Theta-phi],
a Cos[t] Sin[Theta-phi] + b Sin[t] Cos[Theta-phi]}


The intersection points are easy. They can be calculated from the transformed parametric form of the Ellipse with parameters t1 and t2 and then the differences between their x-coordinates is the length of the line L.

Now we have everything to calculate the area of the shaded region as the integral of the radius vector of the ellipse r=Sqrt[x^2+y^2] along the parameter interval {t1,t2} minus the area of the triangle (0 t1 t2) which is yl L / 2. The interval {t1,t2} is determined by the condition that the y-coordinate of the parametric ellipse equation must be equal to yl

Solve[a Cos[t] Sin[Theta-phi] + b Sin[t] Cos[Theta-phi] == yl, t] /. C -> 0 // Simplify


The integral can be carried out analytically (it is actually an Elliptic integral)

 Integrate[ Sqrt[(a Cos[t] Cos[Theta-phi] - b Sin[t] Sin[Theta-phi])^2 +
(a Cos[t] Sin[Theta-phi] + b Sin[t] Cos[Theta-phi])^2] // Evaluate, {t, t1, t2},
Assumptions -> {{a, b, t1, t2, Theta, phi} \[Element] Reals, t2 > t1,a>0,b>0}]


yielding the area

a (-EllipticE[t1, 1 - b^2/a^2] + EllipticE[t2, 1 - b^2/a^2]) -  yl L /2


which is independent of the rotation angle Theta.

• thanks for your response. What do xe,ye,t1 and t2 refer to? Mar 28, 2015 at 14:17
• xe, ye are refering to the center of the ellipse (see text). t1 and t2 are the two solutions of the equation in the last solve statement in the text. Mar 28, 2015 at 16:56
• Am I right to assume that the analytical equation for the region shaded in yellow to be: a (-EllipticE[t1, 1 - b^2/a^2] + EllipticE[t2, 1 - b^2/a^2]) - yl L /2 ? Mar 29, 2015 at 13:06
• Yes, you are right. The first term is the integral solution and the second term is the area of the triangle (0 t1 t2). Mar 29, 2015 at 14:46

Rainer showed that we can use our calculus skills to set up the proper integral and evaluate it analytically.

But we can also solve this problem using the Region functionality in Mathematica to solve the problem. Let's take an arbitrary ellipse and a couple of points, as stated in the OP

ellipse = TransformedRegion[
Ellipsoid[{14, 14}, {5, 2}],
RotationTransform[\[Pi]/3]
];
{p1, p2} = {{-2, 17}, {-8, 16}};
Graphics[{Red, ellipse, Black, Line@{p1, p2}, Green, PointSize[Large],
Point@{p1, p2}}, Frame -> True] We can find the length of the line inside the ellipse by

ArcLength@RegionIntersection[InfiniteLine[{p1, p2}], ellipse]
N@%
(* (40 Sqrt[259 (-6425 + 3828 Sqrt)])/(2881 - 252 Sqrt) *)
(* 3.77312 *)


To get the area, we form a HalfPlane from the line, visualized below

Graphics[{Red, ellipse, Black, Opacity[0.5],
HalfPlane[{p1, p2}, {0, -1}]}, Frame -> True] N@
Area@RegionIntersection[HalfPlane[{p1, p2}, {0, -1}], ellipse]
(* 3.81495 *)
`

It's easy to verify that the sum of the areas found by using the two half planes from this line add up to the total area of the ellipse.