Public Group

# Finding the angle

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

## Recommended Posts

The info that i have: vector2 a,b, d(middle); int length;// length of the 90degree angle How would I calculate a 90 degree angle from "a,d"? "h" is just to show how it should look like. note: h != (b.x, a.y)

##### Share on other sites
There are an infinite number of points which satisfy your criteria. What are you trying to do? What do you mean by the "length of the 90 degree angle" or "calculate a 90 angle?"

##### Share on other sites
If you have a vector (a, b), then you can just scale (-b, a) appropriately to give you an orthogonal vector of a given length (EDIT: assuming that this is what you're asking for).

You can then just add this vector to the midpoint position vector of AB (i.e. d) to get h.

##### Share on other sites
All I can say hoping that this isn't homework is this.

1.) Do you know what the dot product is?
2.) do you know what magnitude is?

If so then to find the angle between 2 vectors you simple do this

theta = cos-1(a.b)/|a||b|)

that is in English terms

the angle = the inverse cosine of the dot product of the 2 vectors divided by the magnitude of both vectors.

Take the dot product divide it by (magnitude a * magnitude b) then with that answer take the inverse cosine of that answer to find the angle.

##### Share on other sites
Im getting a really odd numbers

(whiteLine is original "a,b", it then points from "b" to MiddleExtension vector)

Vector2 MiddleExtension = new Vector2();                float AngExtenstion = FindAngleOnLine();                MiddleExtension = T_Position[0];                MiddleExtension.X += (float)AngExtenstion * 2;                MiddleExtension.Y += (float)AngExtenstion * 2;

// I'm assuming I got this correct// A is index[0] B is index[1]public float FindAngleOnLine()        {            if (T_Position.Count >= 2)            {             float dotnumber =  -1 * (T_Position[0].X * T_Position[1].X) + (T_Position[0].Y * T_Position[1].Y);             float AMag = (float)Math.Sqrt((float) T_Position[0].X + T_Position[0].Y);             float BMag = (float)Math.Sqrt((float)T_Position[1].X + T_Position[1].Y);             return dotnumber / (AMag * BMag);            }            else                return -1;        }

##### Share on other sites
Quote:
 Original post by pascalosti vector2 a,b, d(middle);int length;// length of the 90degree angleHow would I calculate a 90 degree angle from "a,d"?

coden4fun had the dot prod. right once you found theta use the sin(theta) for height. note sin(90) is one.

[edit/] after a good night sleep I had though about your question again. If your looking for a midpoint [(b + a)/ 2] seems weird but in third space (x1+x2)i/2 + (y1+y2)j/2 +(z1+z2)k/2 = midpoint in a 3D vector where P1(1,2,3) and P2 (2,3,4) i would look like this (1+2)i/2 = 3/2i so your new vector Q1 (3/2,5/2,7/2) is the midpoint. [my note: 864][/edit]

[Edited by - ironhand69 on November 4, 2007 7:20:28 AM]

Thank you

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634104
• Total Posts
3015541
×