Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

math problem 1

Status
Not open for further replies.

ericxbenoit

Programmer
Nov 4, 2001
5
0
0
CA
Hi,

I would like to know how I can do to know if 3 points (x,y) do a 90 degre angle?

Also, if 4 points (x,y) have 2 sides parallel..

If someone have an idea, let me know!

Thank you!
 
1- The (scalar?) product of two vectors formed by the points must be 0, that is:
Code:
  v1=p2-p1;
  v2=p3-p1;
  product=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  if(product==0)
    //Their angle is 90 degreees

2- Something similar. You construct two vectors using two points both. Vector from p1 to p2 is equal to p2-p1.

Then, you normalize this vectors, that is, you make that vector to have size 1. You must divide its x,y and z by its size, which has this formula:
Code:
  sqrt(v.x^2 + v.y^2 + v.z^2);
When you have both vectors normalized, then you calculate their product, and if it's -1 they're parallel.
 
Thank you !

For the point 2, can you show me an example like the point 1?

Really thank!
 
Of course, here it is:
Code:
  v1=p2-p1;
  v2=p4-p3;
  size1=sqrt(v1.x^2 + v1.y^2 + v1.z^2);
  size2=sqrt(v2.x^2 + v2.y^2 + v2.z^2);
  v1=v1/size1;
  v2=v2/size1;
  product=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
  if(product==-1)
    //They form 180 degrees, so they're parallel.
  //If they aren't, repeat process using:
  //
  //v1=p3-p1;
  //v2=p4-p2;
If you want to know why this works, the "secret" is that the product has this two formula:
product=v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
product=size1*size2*cos(angle);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top