rotating a point around another point
science_geek
Posts: 247
im trying to get the prop to rotate· a point around a different point. the equations im using are X'= X*COS(a) - Y*SIN(a)
[font=Arial,Helvetica][size=+1]····· Y'= X*SIN(a) + Y*COS(a)· im having trouble getting sin and cos. i know there are sin lookup tables but i have no idea where to start to get this information. can someone help me figure out how to get a sin and cos value that i can plug into this equation so i can do point rotation.[/size][/font]
any help is much appreciated
[font=Arial,Helvetica][size=+1]····· Y'= X*SIN(a) + Y*COS(a)· im having trouble getting sin and cos. i know there are sin lookup tables but i have no idea where to start to get this information. can someone help me figure out how to get a sin and cos value that i can plug into this equation so i can do point rotation.[/size][/font]
any help is much appreciated
Comments
Don't trust the other trig functions. They aren't complete/tested.
The idea is that you supply the radius of a circle to the library functions so that it can return an integer value after it computes the cos/sin/tan and not just a number between 0 and 1 since that is not an integer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,
Ok it's written in Python but I'm sure you can see how to do it in Spin/PASM. Adjust the "203" to change the number of steps and adjust the "5"s to change the step size.
Scale your points x's and y's coming in and going out. If you want to rotate around a point other than the origin just translate the point accordingly on the way in and the results on the way out.
No idea what your application is but this is neat for continuous animation of say a moon around a planet or a star field. Some place where you don't require a totally smooth circular path.
Attached is a plot of the points produce by the above.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Thanks to the method you posted, I understand the CORDIC method better than before. It is interesting, that I've never seen such simple,·attractive and convincing graphical demonstration of the root of the algorithm.
A short summary for the expansion from your method to CORDIC:
One can add that the stepsize n· should be· small to make the rotation matrix as simple as
1 - f
f + 1
where
f=1/2^n
is the angle step in approximate radians.
For small f angle
COS(f) approx. 1
SIN(f) approx. f
and one needs 2*Pi/f steps to draw a circle.
To rotate a vector through an· arbitrary angle of f, we calculate:
x' = x * COS(f) - y * SIN(f)
y' = x * SIN(f) + y * COS(f)
and this simplifies for small f. Since f=1/2^n,·one can do the multiplication with it with simple right shifts (division). When we want to proceed in larger steps toward a specified angle theta, then come the successive approximation(iteration) and the precomputed tables of sines/cosines into the picture.
Cheers,
Istvan
To my mind it works because the differential of sin(a) is cos(a) and the differential of cos(a) is minus sin(a).
(Differential = rate of change). Then x is proportional to sin(a) and y is proportional to cos(a). So we can add a wee bit of y to x to get our next x and subtract a wee little bit of x from y to get our next y.
Don't you just love this "hand waving" maths.
Now a problem: Looking at that last circle plot I posted it seemed to be a bit distorted and so it is. When the radius gets smaller the distortion gets worse. So if you were doing this for rough circles using 8 bit arithmetic things start to look like the attached. There I have plotted an accurate circle for comparison. Radius = 50 in both cases. As you see the first quadrant is pretty good but the other three are too close to the origin.
I don't expect my circles to not be rough using small integer arithmetic but is there a way to pull this into shape?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
BUT, one application I mentioned earlier is animating a moon around a planet or lots of points in a star field background. In which case we really only want one point at a time continuously moving.
Of course one could move the "moon"/"star" through approx 90 degrees and then reset the x and y to 1, 0, -1, appropriately and continue, which seemed a bit clunky to me.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.