Example 01 - http://www5.picturepush.com/photo/a/1296823/img/1296823.png Example 02 - http://www1.picturepush.com/photo/a/1296819/img/1296819.png
My name is aNewHobby. I am not a mathamatician, or a student, or anything like that. What I am is a colledge drop out and a zoo keeper, who has a strange hobby that some of my mates think is very wierd. I make freeware homebrew computer games. Anyway. I am currently working on a project during my spare time at the moment and have come up against a mathamatical problem i just can not solve.
I have no one to turn to, I have tried asking on maths forums but no one seams to be able to help. I was hoping you may be able to point me in the correct direction to find someone who might be interested in solving my problem for me? I have tried for weeks now and read book after book, but I haven't really done maths for like 15 years so it is a hard slog for me.
Anyway... here is the problem... I really hope you may be able to solve to for me or at least put me in touch with someone who may help me.. For like I said I am just unable to do it and do not know where I am suppose to go for Math help.
So thanks in advance if you decide to help, and if not thanks for your time. If you know a way better way of doing thins.. then please let me know.
The Problem (please look at attached images as I explain)
I have a computer screen represented in X,Y grid coordinates. 0,0 (x,y) is the very top left of the screen and 1280,800 is the very bottom right of the screen. (this is a range as well anything outside this is no good as it will not render on screen)
I have two points with known X,Y values on this screen. (Lets call them A and B) So I know the values of Xa,Ya and Xb,Yb.
What I am trying to do if find the X,Y cords of an ARC that passes though A and B.
Now I know that without a third point this is not possible so let me go on....
The LINE that connects A and B is the base of a isosceles triangle. And we know the values of the equal angels.
So to Recap, What do we know?
1) The X,Y values of A
2) The X,Y values of B
3) The value of the 2 angles marked D
So What do we need to do?
1) Use the X,Y Vales of A and B to work out the distance between those points.- Lets call that S
2) Using S and the values of D we can work out the X,Y cords of H.
3) Using the X,Y cords of A,B and H we work out the X,Y cords of any Point along the line of the arc that moves through all three points.
Some other things.
In the game the situations will always be like in the drawing. as in A is always on the RIGHT and B is always on the left.
A and B will always be slightly different from each other. A and B should nvr share and X or Y value.
(dunno if that help? maybe it makes it more simple?)
What exactly am i asking for?
I am looking for some formulas that
1) I can plug in the A,B (x,y cords) and D (angle values) into and return the X,Y of the point we are callign H
2) A Formular that uses the A,B and H x,y values to return a New X,Y value that sits on the arce that moves between all points. (Say Xp,Yp)
3) A way to move though the entire possible points on this arc.
OK.. here is my lame Math.... remember I have been looking up websites to learn wtf COS is and stuff like that... I have no math training and suck at all this, it is probably totally gibberish to you but I wanted to show you that I have been trying.
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.
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)