Finding the angle

Started by
5 comments, last by pascalosti 16 years, 5 months ago
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)
Advertisement
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?"
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.
[TheUnbeliever]
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.
Im getting a really odd numbers

(whiteLine is original "a,b", it then points from "b" to MiddleExtension vector)
Free Image Hosting at www.ImageShack.us

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;        }
Quote:Original post by pascalosti

vector2 a,b, d(middle);
int length;// length of the 90degree angle

How 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]
I went with your first advice, using Matrix is much easier.

Thank you

This topic is closed to new replies.

Advertisement