Archived

This topic is now archived and is closed to further replies.

Damocles

finding the sin/cos of a point on a circle

Recommended Posts

I need to know how, if you had a circle as x,y,r and a point in 2d space of x,y which will reside somewhere on the perimeter of the circle - how can I get the sin/cos values of that point relative to the centre? That probably doesn''t make much sense, so here''s what I''m doing: I''m making a 2D game and the baddies in the game will have spherical shield systems. I want to make these look reeel purdy by making it so when a projectile strikes the shield, I get the point of impact and then generate multiple particles at that point. these particles will then spread out across the shield sphere to make a nice shield hit effect. I have figured out how to make the particles move around the sphere''s surface using sin/cos but I can''t figure out how to get the initial sin/cos values once I have established the point of impact. Anyone understand me and can help please? Also, I only need to get the sin/cos for the x/y of the impact. Being a 2D game we can chuck the z vector and assume all impacts occur at the equator line of the shield.

Share this post


Link to post
Share on other sites
It''ll try to draw a picture to make this easier to understand:

o (x2,y2)
/|
len=r / | len=(y2-y1)
/ |
(x1,y1)O---o (x2,y1)
len=(x2-x1)

(x1,y1) being the center of your circle, (x2,y2) being the point on the perimeter...

So, assuming you want to find the sin/cos/tan of the angle at (x1,y1) You would use the following forumulas sin(angle)=opposite/hypotenus cos(angle)=adjacent/hypotenus and tan(angle)=opposite/adjacent

For the angle at (x1,y1), "adjacent" or the length of the adjacent size, is (x2-x1), opposite is (y2-y1) and hyp. is "r"
So sin(angle) = (y2-y1)/r cos(angle)=(x2-x1)/r and tan(angle)=(y2-y1)/(x2-x1)

Finding the angle itself is as easy as taking the inverse sin/cos/tan of the result

Share this post


Link to post
Share on other sites
Here''s a routine to return an angle, if (x1, y1) is the origin of your circle and (x2, y2) is a point on the circle.


  
double getAng(double x1, double y1, double x2, double y2)
{
double x = x2 - x1;
double y = y2 - y1;
double dist = sqrt(x * x + y * y);

double ang = acos(x / dist);

if (y >= 0)
return ang;
else
return -ang + 2 * PI;
}

Share this post


Link to post
Share on other sites