If you know the X,Y location values, on a 2D grid of point, A and B how can you work out the X,Y locations along the grid of a curve that ends in both point? So you can plot a curve from A -> B along a perfect ARC.
Example 01:- http://www5.picturepush.com/photo/a/...mg/1296823.png
Example 02:- http://www1.picturepush.com/photo/a/...mg/1296819.png
I am not really a maths guy. I have just run into this problem and need a solution and have had to basicly re-learn maths from scratch. Trying to remeber from when I was at school.
So I have NO idea if I am even on the right track or way off base.... or if my method to get the points on the arc are correct. So if you have another solution for this instead of fixing my math, i would also love to see your math.
This is How I have been doing it so far...
My Steps
1) I have assumed a value called H. This is the X,Y Location point of the top of a isos triangle, whose base line makes up the line from A-B.
2) I have "invented" a value for the degrees of the = angles that of the isos triangle. I figure by changing this angle I can make the arc more or less rounded.
3) I use the ANGLE D and the Length of the LINE A - > B to find the height of H.
4) Then using A,B and H. I can then plot the points of all the X,Y cords along the ARC.
This is My method... and here is my lame math... that doesn't seam to work.
Ok, working out the location of H from the angles D
1) work out distance between A and B, let's call this Di1:
Di1 = sqrt((Xb - Xa)^2 + (Yb - Ya)^2)
2) work out midpoint of AB line, let's call this M
(Xm , Ym) = ((Xb + Xa) / 2 , (Yb + Ya) / 2)
3) work out gradient of line AB, let's call this g1
g1 = (Yb - Ya) / (Xb - Xa)
4) work out gradient of line perpendicular to AB, let's call this g2
g2 = -1 / g1 (note: this value won't exist if g1 = 0, need a special case, see below)
5) work out angle between line perpendicular to AB and horizontal, let's call this phi
phi = atan(g2), if g2 exists (I.e. if g1 is not 0)
= 90 degrees = Pi/2 radians, if g1 is 0
6) get distance between midpoint (M) and H, let's call this D2
Di2 = Di1 * tan(D) / 2
7) get coordinates for C
(Xc , Yc) = (Xm + Di2 * cos(phi), Ym + Di2 * sin(phi))
note, you'll get a semi circle when D are 45 degrees.
OKKKKKaaaayyyyyy
Now how to get the points on the ARC itself....
1) Work out the centrepoint of the arc (let's call this point C) - this is the point that is the same distance from points A,B and H.
Xc = [(Yb - Yh)(Xa^2 + Ya^2) + (Yh - Ya)(Xb^2 + Yb^2) + (Ya - Yb)(Xh^2 + Yh^2)]
-------------------------------------------------------------------------------
2*[Xa*Yb + Xb*Yh + Xh*Ya - Ya*Xb - Yb*Xh - Yh*Xa]
Yc = [(Xb - Xh)(Ya^2 + Xa^2) + (Xh - Xa)(Yb^2 + Xb^2) + (Xa - Xb)(Yh^2 + Xh^2)]
-------------------------------------------------------------------------------
2*[Ya*Xb + Yb*Xh + Yh*Xa - Xa*Yb - Xb*Yh - Xh*Ya]
2) Work out the radius of the arc, this can be done by calculating the distance between C and A (or C and H, or C and B).
r = sqrt((Xb- Xc)^2 + (Yb - Yc)^2)
3) Work out the the start and finish angles around the arc. The easiest way to do this is using a function called ATAN2 if you are using C or something similar.
Start angle = angle between horizontal and the line joining C and A = atan2(Yb - Yc, Xb - Xc)
Finish angle = angle between horizontal and the line joining C and B = atan2(Ya - Yc, Xa - Xc)
4) any angle between the start angle and finish angle will give you a point along the arc, so you can use code like the following pseudo code to generate these points:
for each angle theta between the start angle and finish angle do the following
calculate the x coordinate as Xp = Xc + r * cos(theta)
calculate the y coordinate as Yp = Yc + r * sin(theta)
output the point on the arc as (Xp,Yp)


LinkBack URL
About LinkBacks



