 # Maybe a stupid question

Hello people,

I want to calculate the angle between two lines, I found some code in the net that can calculate the angle between two vectors, now how can I procede, witch is the diference between a line and a vector ? does someone know a way to calculate the angle between two lines ?
Thank you for the moment
Best regards
Kurt

A line is actually a vector, or at least you describe the direction of a line with a vector, so use the same code for lines as for vectors.

hello,

I sorry i don’t speak very well english!

A line is define with 2 points… For make a vector with a line make that:

A (xa,ya,za)
B (xb,yb,zb) //2 points

vector1 (xv,yv,zv)

vector1.x = -xa +xb;
vector1.y = -ya +yb;
vector1.z = -za +zb;

vector2.x = …

//and for calculate the angle
//make the scalaire multiplication
//between two vectors

phi = acos ((vector1vector2)/(|vector1| |vector2|)); // is the scalaire multiplication

Best regards

Jérôme

Thank you !
I will try something in this way.
Best regards
Kurt

Hello

phi = acos ((vector1vector2)/(|vector1| |vector2|)); // is the scalaire multiplication

ok you have vector1*vector2 / by what ? |vector1| * or / by |vector2|

Thank you for the moment
Best regards
Kurt

Hi,

ok you have vector1*vector2 / by what ? |vector1| * or / by |vector2|

In analytical geometry, there are a scalaire multiplication… I’m sorry… I don’t really know how to say it in english.

• is the scalaire multiplication you make that:

vector1 * vector2 = xaxb + yayb + za*zb;

|vector1| = sqrt(vector1.xvector1.x + vector1.yvector1.y +vector1.z*vector1.z); //is the module of the vector

and then you make |vector1|.|vector2|; //it’s a simple multiplication for two number!

You understant?

If you have any question… e-mail me!

Best regards
Jérôme

Hey,

phi= acos(v1.v2/(|v1|*|v2|))

where v1.v2=v1xv2x+v1yv2y+v1z*v2z

Maybe it’s clearer now, however, be aware that the function acos() returns an angle between zero and pi=3.14159… and if the actual angle is, say, 5pi/4, acos() will return 3pi/4 because they both have the same cosine and acos() couldn’t tell which one you want. So, you will need to know the sine of the angle as well, which is obtained by deviding the length of the cross product of the two vectors by the product of the lengths of the two vectors. If you want to know how this is done drop me a line.

it’s called dot product.
DMY

Originally posted by dmy:

it’s called dot product.
DMY

Thank you DMY,

I learn every days…

Best regards
Jérôme

Hi,

DMY, how do you say in english the another product.

1. dot product

2. vectoriel product (it’s correct?)

Have a good day!

Best regards
Jérôme

the most common name i found in graphics textbooks is cross product.

so recap, the most common operations with vectors in graphics are two: the dot product and the cross product.

dot/inner/scalar product is the componet-wise product:

a dot b = s (scalar) =
a.x * b.x + a.y * b.y + … =
|a| * |b| * cos(phi)

cross/vector/outer product, gives the plane-bundle where the two vectors are built, or the normal to that plane, wich is basically the same.

a cross b = n (vector) =

(for the 3-space case)

n.x = a.yb.z - a.zb.y
n.y = a.zb.x - a.xb.z
n.z = a.xb.y - a.yb.x

|n| = |a| * |b| * sin(phi)

DMY

[This message has been edited by dmy (edited 12-21-2000).]

Ok guys,

WE got it working, thank you for everybody that replies, especial thanks for Boubou and softland_gh. Best regards
Merry Christmas and have a nice 2001.
Kurt

Ok,

Everything with the angle is working, in order to try I have drawn two lines in AutoCAD system, in AutoCAD I have the following lines |_, (with 90 degrees) but then when I use the coordinates that is the AutoCAD system I have the following lines in my system (also with 90 degrees but in a wrong way:
_
|

The code for the projection is :
glOrtho(500.0, -500.0, 500.0, -500.0, -1.0, 100.0)

Can someone explain me a bit ?
Thank youfor the moment
Best regards
Kurt

PS.: if someone want a picture of a screen shot of both systems (my application and AutoCAD) I can send it by email, just ask me.

The OpenGL coordinate system is set up in a different way. By default the Y axis goes up, not down. Flipping all your Y coordinates should take care of it I think what Dodger said is right. Maybe it’s matter of right-handed coordinate systems and left-handed coordinate systems. You have to flip one axis.