• ### Popular Now

• 9
• 13
• 18
• 19
• 27

#### Archived

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

# Can an angle be mirrored?

This topic is 5108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

This is a really simple question. I'd like to know if an angle can be mirrored right-left without a switch-case statement. The angle is limited to 45 degree increments. if = new 45 = 315 90 = 270 135 = 225 225 = 135 270 = 90 315 = 45 0 = 0 180 = 180 Thanks for any help! [edited by - Jiia on March 20, 2004 3:06:52 PM]

##### Share on other sites
new_angle = 360 - old_angle?

[edited by - Muzzafarath on March 20, 2004 3:09:53 PM]

##### Share on other sites
LMAO! Thanks I appreciate it.

##### Share on other sites
Can I ask another simple question that will make me further look like an idiot?

How can I use two velocities (x & y) to determine a 0-360 angle? The velocities can be positive and negative, and can be any range.

Thanks again!

##### Share on other sites
Finding the angle? If I understand you correctly, the below code should work, I'm not entirely sure, but in theory I think it will.

float tangent = y / x;float angle = 1 / tangent;

That should give you the angle. Just a warning, this code only works with first quadrant angles. If you want other quadrants, you will have to write some testing and so forth.

(Stolen from Programmer One)
UNIX is an operating system, OS/2 is half an operating system, Windows is a shell, and DOS is a boot partition virus

[edited by - Dragon88 on March 20, 2004 6:09:34 PM]

[edited by - Dragon88 on March 20, 2004 6:10:17 PM]

##### Share on other sites
quote:
Original post by Jiia
Can I ask another simple question that will make me further look like an idiot?

How can I use two velocities (x & y) to determine a 0-360 angle? The velocities can be positive and negative, and can be any range.

Thanks again!

I assume you mean that x and y are the components of one velocity.

If so, the angle would be arctan(y/x).

Here''s why.

Given a triangle where the hypotenuse is the actual velocity, and each leg is a component of that velocity (x and y), the angle formed between the resultant velocity and the x-axis would be the angle you''re looking for.
The tangent of that angle is equal to the opposite side (y) over the adjacent side (x). Therefore, the angle is equal to the arctangent of the ratio y/x.

##### Share on other sites
quote:
Original post by Dragon88
float tangent = y / x;float angle = 1 / tangent;

...won''t work. It should be (for example)
float angle_rad = atan2(y,x);float angle_deg = angle_rad*180/PI;

The result is in range -180...180.
There''s also a function, atan(), which will take the tangent as parameter and return a value in range -PI/2...PI/2. In this case you have to determine the quadrant yourself.

##### Share on other sites
This seems to return an angle of -78 with XVel=40, YVel=-40:

angle = (LONG) atan(DOUBLE(Vel.Y)/DOUBLE(Vel.X)) * 100.0;

Did I screw something up? Is up negative or positive? What is the value range of atan?

Thanks for all of the help, much appreciated!

EDIT: I totally forgot to mention that my straight-up angle is 0. Straight down is 180. But that could be easily fixed by adding or subtracting. I also need to watch out for X-velocity to be zero, correct? Should I just make a special case and set 0 and 180 manually?

[edited by - Jiia on March 20, 2004 6:40:59 PM]

##### Share on other sites
atan() returns the angle in radians. To convert it to degrees, you do
angle_deg = angle_rad*180/PI;

EDIT: Typo. BTW if you'll stay with atan() instead of atan2(), you'll have to determine the quadrant of the angle yourself (basically you check whether vel_x and/or vel_y are positive or negative and such; drawing things on paper will help).

[edited by - nonpop on March 20, 2004 6:55:10 PM]