Here we are looking down upon a scene with a camera at the bottom looking up at a board with a central pivot point, there is an object on the bottom left corner of the board, the black square thing | |||
Now we can instruct the camera to look at any coordinate in this view. So to track the object as it moves around the screen on the board we need to know where it is in two dimensional space (as opposed to an angle). This exactly the situation I found myself in using OpenGL 3D code, I would instruct the board to rotate but then the camera did not know where to look (plus the camera has to look first in OpenGL) |
This just draws a circle point by point, one degree at a time | This draws the each point from the center and shows that the there are tiny holes in our circle. If the circle had a 4 mile radius imagine the distance between each line ! | Click in the eight segments and you will see the angle found is always between 0-180(blue) | Click in these eight segments and the code will compensate, working out your click via the radius and the angle. |
rotation01.java | rotation02.java | rotation03.java | rotation04.java |
r=Math.sqrt(Math.pow(length((int)sx,(int)cx),2)+Math.pow(length((int)sy,(int)cy),2));
precalc = length((int)sx,(int)cx) / r;
angle = (180D/Math.PI) * Math.asin(precalc);
sin(x) = Opp/Hyp
and is where I hit my first hurdle, although most books and people will tell you to use sin to the power of minus one
that is a short cut of saying use the asin function in radian mode.Opp/Hyp
and the second line converts the answer to degrees.
rangle = angle * Math.PI /180D;
xa = Math.cos(rangle) * r + cx;
ya = Math.sin(rangle) * r + cy;
Where angle is first converted from degrees to rangle in radians and then the X coordinate can be calculated with cos and the Y coordinate with sin (r = radius and cx,cy are the center of the circle).
email
root
In fact I'm not responsible for anything ever, so there!
Disclaimer:
This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk
I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk