# Math Help - Distance between 2 point along an oval

1. ## Distance between 2 point along an oval

Hi All...

I am looking for a formula to calculate the distance between 2 points on the outside of an oval.

I made a small example image.
I have the X,Y value of both A and B.. so in this example they are:
A.x = -1.9
A.y = -2.8
B.x = 2.0
B.y = 2.5

I also have the radius of the oval... we can call R and equals 9.42 (should note I made that up, but I know that the radius of a 6x6 circle)

I am trying to find a way to calculate the distance from A to B clock wise along the surface of the oval, and not necessarily the shorted distance.

I found a formula for calculating the distance for two lat and log and tried to adapt that, but it didn't work... here is what I had:

acos(sin(A.x) * sin(B.x) + cos(A.x) * cos(B.x) * cos(B.y-A.y)) * R

Honestly.. this type of math is above my head, but I really need the answer so I am giving it all I have... been reading up on cos and sin and know its like the x and y of my A and B... but everything I find talks about how to calculate out the angle from the center to get the x and y.. which I already have ....

2. Hi,

first of all, do you mean "circle" when you say "oval"? And in your example A and B don't lie on a circle centered at O; is it a mistake?

If you're looking for the distance along the circle (centered at O) between two points A and B on it, your formula is not quite correct. It should just be:

$d_C(A,B)=R\arccos\left(A_xB_x+A_yB_y\right).$

(this is a consequence of $\cos(a-b)=\cos(a)\cos(b)+\sin(a)\sin(b)$)

Does it seem OK?

3. ## :) OK...

Ok, I know I am know I am going to end up sounding like an idiot, but I don't understand most of your math

When I said oval, a better word would have been ellipse. In the example image your right its more of a circle, but my ellipse could be a circle and could be any size in the x and y axis.

Its center would be 0.0

For your math, can you write it out in say a javascript code format? I only have basic HS math education, and while I have learned tons (I actually make tools for 3d environments), something I have never learned is the complex notations like yours. Something I know I should study sometime, but for programming its real world applications, not formulas (which I know is what I asked for lol).

You wrote:
cos(a - b) = cos(a) cos(b) + sin(a) sin(b)

Now comes the stupid questions:
1. a and b both have 2 values x and y... but you never express those.. are you summing those values, or applying to both values?
2. cos(a) cos(b) <-- what does that mean, are you adding them? multiplying? same with sin(a) sin(b)

I admittedly feel really stupid for not knowing these things..

It should also be noted that in my real life application of this A is actually always going to be in the same spot at A.x = 0 and A.y = ellipse.y / 2.0.
ellipse.y is the full width along the Y axis. But B can be anywhere along the ellipse.

It should also be noted that I posted this in the HS section as well, not getting any answers I posted it here. I did get a response on there as well which I understood even less.

He said:
It's more complicated than you might think...

The formula for the length of part (L) of a curve is

The equation of an oval, more correctly called an ellipse, is

Rearranging gives

This becomes difficult to work with as an ellipse is not the graph of a function. If one point is below the x-axis and the other above then you have to use both square roots separately, because an ellipse is the joint graph of those two square roots above...

4. ## Also...

Also thought I would add in the past I figured out almost the opposite of how to do this, having a percentage around the ellipse what the x and y would be:

corner0.x = 0.0
corner0.y = ellipse.y / 2.0
corner1.x = ellipse.x / 2.0
corner1.y = 0.0

c.x = ((corner0.x - corner1.x) * cos(TWO_PI * PERCENTAROUND )/2);
c.y = ((corner0.y - corner2.y) * sin(TWO_PI * PERCENTAROUND )/2);

5. The person who said that this problem is more complicated than you might think was putting it mildly. There is a standard technique in calculus for finding the distance along a curve. It involves calculating an integral. Unfortunately, the integrals for finding distances along an ellipse cannot be expressed using any of the standard functions in mathematics. They are known as elliptic integrals, and the only practical way to evaluate them is to use numerical methods to find an approximate value.

6. Ok, oh well...

I am sure I can at least hack something together that gets me close with the math I posted just prior to this. I am just using this to display an interface over a cylinder where they touch and wanted to align the texture so it is centered where they touched.

7. Originally Posted by skidx
Ok, oh well...

I am sure I can at least hack something together that gets me close with the math I posted just prior to this. I am just using this to display an interface over a cylinder where they touch and wanted to align the texture so it is centered where they touched.
So your ellipse is in fact a circle from 3-d space drawn in perspective. Do you need the length along the ellipse between two points on the 2-d drawing (then it's far from trivial, as Opalg said), or do you need the "real" length (i.e. in 3-d) between two points on the top of the cylinder, along this circle (then this can be reduced to the formula I gave)?

There is no simple link between these two lengths (contrary to areas); one is easy to compute, while the other is highly complicated. I hope in fact you only need the easy one...

8. If the question is regarding the standard ellipse
$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$

then obtain the equation of the line joining the two points $A$ and $B$ and express the equation of the line in the form $y=mx+c$

then you have a standard result

$
AB=\frac{2ab\sqrt{1+m^2}\sqrt{a^2m^2+b^2-c^2}}{a^2m^2+b^2}
$

If the equation is of the form $Ax^2+2Hxy+By^2+2Gx+2Fy+C=0$ then this equation can be converted to the standard equation described as $\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$ by using shifting of origin transformation and rotation of axes transformation and the above method may be applied