This message was edited by gautam at 2006-8-7 3:33:44
This message was edited by gautam at 2006-8-7 3:30:52
The ratio is called eccentricity. Well its not exactly a ratio but rather it denotes how elongated the ellipse is. You will have to take care of this to get a better approximation.
Equation of an ellipse and circumference of the ellipse -http://en.wikipedia.org/wiki/Ellipse
The equation of a circle with the centre at origin is x*x + y*y = r*r
: :
This message was edited by IDK at 2006-8-6 11:5:47
: : : : 1. This is rather simple trigonometry, but I haven't been teached trigonometry so I don't know how it's done. This is how I would do it with my rather weak knowledge of trigonometry:
: : : :
: : : : z---y
: : : : | /
: : : : _|_/
: : : : / |/\
: : : : | x |
: : : : \___/
: : : :
: : : : Point z is gotten from x value of y and y value of x

: : : : Then sin(a) = z.y-y.y / sqrt((x.x-y.x)^2+(x.y-y.y)^2)
: : : : Since z.y = x.y it can be replaced, and z isn't needed.
: : : :
: : : : 2. If you use y=cos(a) and x=sin(a)*2 to draw the ellipse, then replace a with the value obtained at 1.
: : : :
: : : Hi Niklas,
: : :
: : : Thank you for your reply. I am not sure I understand this entirely but I am starting to get the picture I think. I am a bit confused about how "y=cos(a) and x=sin(a)*2" work in relation to what I am trying to achieve. I am assuming that "a" is the angle in radians, and as I am looking for a point on the edge of an ellipse so surely the formula to find the point needs to account for the position of the center point of the elliipse and the X/Y radius?
: : :
: : : Gerry
: : :
: : :
: : Yes, you'r right.
: : It should look like this:
: : x=centerX+cos(a)*radius
: : y=centerY+sin(a)*radius*//(can't remember the name in swedish, and I don't know the name in english, but some kind of ratio)
: :
: :
: : Another thing, how does the formula with a circle look like?
: :
: Hi Niklas,
:
: Thanks for the update, I eventually figured it out and got it working but there are a couple of points worth noting.
:
: // Get angle in radions
: float angle = getAngle(lc.st.X, lc.st.Y, lc.end.X, lc.end.Y);
:
: // Find position
: int x = ( lc.x + lc.xRadius * sin(angle) );
: int y = ( lc.y + lc.yRadius * cos(angle) );
:
: The "angle" is in radions (I found the above function on the net an adapted it for my purposes).
:
: This does the job but this calculation seems to be an approximation. The XY posiion always ends up exactly on the perimeter of the ellipse but it does not always intersect the line exacyly. From what I can make out in the debugger, the angle is correct but the resultant position of the calculated point around the ellipse is slightly off.
:
: If the ellipse is a circle (i.e Xradius and Yradius are equal) then its 100% accurate), if its an ellipse, then the points 0, 90, 180 and 270 degrees are spot on but the points in between those are not perfect. The more elliptical the shape the more error there seems to be.
:
: In answer to your point about the circle, its very accurate.
:
: In answer to your point about the ratio, its provided by virtue of the fact that the calculation takes into account the X and Y radius.
:
: I could not figure out why the inaccuracy occurs but from what I can find on the web it seems to be generally accepted that caclulating this exactly is very difficult. It seems to relate to the fact that the angle calculated is linear on the XY plane but the angle around the ellipse is not because of the XY ratio. It looks like the angle value may need some kind of sine adjustment based on the ratio of the XY radius.
:
: Anyway, thank you very much for your help, you got me going in the right direction. Although not a perfect solution this works for my purposes and is good enough (although it will secretly bug me until I find the answer

).
:
: Gerry
:
:
:
: