View Full Version : Maybe a stupid question
KurtCob
12202000, 02:21 AM
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.
Boubou
12202000, 03:01 AM
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 ((vector1*vector2)/(vector1 vector2)); //* is the scalaire multiplication
I hope is correct and perhaps it's help you
Best regards
Jérôme
KurtCob
12202000, 03:04 AM
Thank you !
I will try something in this way.
Best regards
Kurt
KurtCob
12202000, 03:12 AM
Hello
phi = acos ((vector1*vector2)/(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
Boubou
12202000, 03:30 AM
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 = xa*xb + ya*yb + za*zb;
vector1 = sqrt(vector1.x*vector1.x + vector1.y*vector1.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... email me!
I hope you understand and it's help you!
Best regards
Jérôme
softland_gh
12202000, 03:32 AM
Hey,
phi= acos(v1.v2/(v1*v2))
where v1.v2=v1x*v2x+v1y*v2y+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, 5*pi/4, acos() will return 3*pi/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
Boubou
12202000, 06:56 AM
Originally posted by dmy:
it's called dot product.
DMY
Thank you DMY,
I learn every days...
Best regards
Jérôme
Boubou
12212000, 12:56 AM
Hi,
DMY, how do you say in english the another product.
1) dot product
2) vectoriel product (it's correct?)
Thank you for your help!
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 componetwise product:
a dot b = s (scalar) =
a.x * b.x + a.y * b.y + ... =
a * b * cos(phi)
cross/vector/outer product, gives the planebundle where the two vectors are built, or the normal to that plane, wich is basically the same.
a cross b = n (vector) =
(for the 3space case)
n.x = a.y*b.z  a.z*b.y
n.y = a.z*b.x  a.x*b.z
n.z = a.x*b.y  a.y*b.x
n = a * b * sin(phi)
(^^^ correct me boys if i'm wrong about this ^^^)
DMY
[This message has been edited by dmy (edited 12212000).]
KurtCob
12222000, 12:16 AM
Ok guys,
WE got it working, thank you for everybody that replies, especial thanks for Boubou and softland_gh.
http://www.opengl.org/discussion_boards/ubb/smile.gif
Best regards
Merry Christmas and have a nice 2001.
Kurt
KurtCob
12222000, 01:07 AM
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.
Dodger
12222000, 07:14 AM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif
softland_gh
12222000, 07:28 AM
I think what Dodger said is right. Maybe it's matter of righthanded coordinate systems and lefthanded coordinate systems. You have to flip one axis.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.