Archived

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

Calexus

points on unit circle

Recommended Posts

Hi, I need to find some points (coordinates) on the unit circle. I need this to determine the direction of a shape (circle for the moment) and yes I really have to do it this way. I have an angle to play with so it shouldn’t be a problem, but it''s. I can''t make it work in the fourth quadrant. If I try to calculate a point at 315 degrees I get a point at (-0,7;0,7) that’s the second quadrant. The strange thing (at least I find it strange) is that I don’t have any problems with points in the third quadrant . Maybe I''m just doing it wrong (or maybe it''s Java playing with me, stupid Java I want my C++) it''s been some years since I''ve done anything like this, and right now I don’t have access to my books or notes. Have I missed something or what? HELP!!!

Share this post


Link to post
Share on other sites
Don''t know if this help''s cuz its in C++. I''ve been working on an asteroids clone, so here''s the code to rotate the ship''s facing vector:



void Ship::turn(int direction, float amount)
{
float rotation_radians = 0;
switch(direction)
{
case LEFT:
rotation -= amount;
break;
case RIGHT:
rotation += amount;
break;
}
//convert the degrees to radians
rotation_radians = (float) rotation * pi/180;

if(rotation > 360) //reset if reached too far.
rotation = rotation - 360;
else if(rotation < 0)
rotation = 360 + rotation;

//think of a unit circle (radius 1)
//The unit vector is the length of the radius
facing.y = (float) cos(rotation_radians);
facing.x = (float) sin(rotation_radians);
}



Here''s the reason why I was doing that: So I could move the ship forward, in the direction it is facing.

void Ship::move_forward()
{
x += facing.x;
y += facing.y;
}

Share this post


Link to post
Share on other sites