# converting degrees to vector normals

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

## Recommended Posts

Hi everybody, is there a formula for converting degrees to vector normals? What i'm trying to do is this: to create an arc from a circle with a center point and radius, and start degrees and end degrees. I can already do this, but it's a long and complicated method and i don't think it's the best way to do it. Thanks for anyone's help.

##### Share on other sites
Are you trying to solve this problem in 2D or 3D?

Also, if you have some working code, you might post it so that we can see what you're doing (be sure to use [source] tags).

##### Share on other sites
This is in 2D. I tried to implement my method, but it doesn't seem to be working...
This code might not be perfect because I don't use C++, but here it is:

// calculates the arc start and end points, given the two degree values// 'a' and 'b' are two class members (vectors)void calcPoints(float aDeg, float bDeg)  {		Vector an = degToVector(aDeg);	Vector bn = degToVector(bDeg);		a = an * radius;	b = bn * radius;}// calculates and returns a normal of direction based on a degree value// 0 degrees is a left-to-right horizontal lineVector degToVector(deg#)  {		Vector startNormal;	        //make the degrees less than 90, storing the rest of the degrees (to the closest multiple of 90) as a normal	If(deg >= 0 && deg < 90)   {		startNormal = New Vector(1,0);        }	ElseIf(deg >= 90 && deg < 180)  {		startNormal = New Vector(0,-1);		deg -= 90;        }	ElseIf(deg >= 180 && deg < 270)  {		startNormal = New Vector(-1,0);		deg -= 180;        }	ElseIf(deg >= 270 && deg < 360)  {		startNormal = New Vector(0,1);		deg -= 270;	}	        //find the side of the triangle formed by a horizontal line (0 degrees) and the remaining degrees	float triSide = tan(deg)*radius;	Vector normal = New Vector(radius, triSide);        normal.normalize();        //return the normal of the sum of the bulk and remainder normals	Return (startNormal + normal).normalize();	}

##### Share on other sites
It sorta looks like you trying to create a unit vector oriented counter clockwize from the x axis by forming a right triangle using the radius as the hypotenuse. A better way to approach this is to use a bit of trig... assuming this is what you are trying to do.

(I am assuming a circle)

r(t) = cos(theta)i + sin(theta)j

If you want normals to arbitrary plane curves, then look into the gradent and level curves.

Edit.
Opps... ViperG is right. No need to nomalize when using the unit circle.

[Edited by - smc on March 8, 2007 1:08:45 AM]

##### Share on other sites
If you just want the vector normal all you do is:

piover180=0.0174532925f; (this is needed to convert radians back to degrees,c functions sin and cos return radians...)

vector.x=sin(deg*piover180);
vectoy.y=cos(deg*piover180);

and they return in doubles, so typecast it to just get a float

vector.x=(float)sin(deg*piover180);
vectoy.y=(float)cos(deg*piover180);

##### Share on other sites
Ok, ViperG's method seems simple, but it's still not working. Do I still need to make the degree value below 90? I tried it with and without that, but neither works. The angles are always wrong, and the vectors go beyond the radius for some reason. I'd post some code, but i tried so many different ways of doing it that i don't know what to post :P

*edit*
nevermind it's working fine after i fixed a dumb mistake i made. It works perfectly now, thank you thank you thank you thank you thank you!!! :P

##### Share on other sites
Just one more question... to convert vector normals to degrees i figured I would just have to do the inverse sine function on the x value or the inv. cosine on the y value. I tried this, but it doesn't work. It seems like the orientation of the normal messes things up. How am i supposed to do this?

##### Share on other sites
Quote:
 Original post by EpilefIt seems like the orientation of the normal messes things up. How am i supposed to do this?
In C, C++, and other languages that offer it, use the 'atan2' function when you need to compute an angle from a 2D vector. It's numerically stable, and takes care of the details of determining the correct quadrant for you.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633679
• Total Posts
3013301
×