Archived

This topic is now archived and is closed to further replies.

WhatEver

How do you make a line perpendicular to a line mathamaticly?

Recommended Posts

I did some searches on google but I didn''t know what words to insert to get a result. I tried a bunch of phrases but none of them came up with what I wanted. What I want to do is determine the distance of a vertex perpendicular to a line. I need to know how so I can select vertices in my terrain editor. Thanks!

Share this post


Link to post
Share on other sites
Linear perpendicularity is determined in (mainly) three ways mathematically. The first, linear algebra, method is two note that if you have a line with slope = m then a line perpendicular to that line will have slope -1/m. The second, calculus, method is to note that if you have a line represented as a vector v[1] with components v[1][x], v[1][y] and v[1][z] then a vector v[2] is perpendicular to that line if v[1] dot v[2] = 0 that is if v[1][x]*v[2][x]+v[1][y]*v[2][y]+v[1][z]*v[2][z] = 0. A third method using vectors is to take two vectors v[1] and v[2] that are in the same plane and take their cross-product, this will give you a vector perpendicular to both.

-- Exitus Acta Probat --

Share this post


Link to post
Share on other sites
You've got my creative juices flowing now.

I started drawing on some graph paper and I think I've determined a way to accomplish what I want.

Steps 1 thru 7 are what I needed, but I continued the steps until I determined the point resting on the line being tested. The point resting on the line and the vertex being tested should create a line perpendicular to the line being tested.


    Vec3f RayStart=some position in space :);
Vec3f RayEnd=some position in space;
Vec3f Vertex=some position in space;
Vec3f PointOnLine;
Vec3f Vector1;
Vec3f Vector2;
Vec3f Vector3;
Vec3f Cross1;
Vec3f Cross2;
float PlaneDistance;
float DistanceToPlane;

Step 1 - calculate ray:
Vector1=RayEnd-RayStart;

Step 2 - create vector relative to RayStart
Vector2=Vertex-RayEnd;

Step 3 - create a vector perpendicular to Vector1 and Vector2
Cross1=CrossFunction(Vector2, Vector1);

Step 4 - create a vector perpendicular to Cross1 and Vector1
Cross2=CrossFunction(Vector1, Cross1);

Step 5 - normalize Cross2
NormalizeFunction(Cross2);

Step 6 - determine plane distance using Cross2 and RayStart
PlaneDistance=DistanceFunction(Cross2, RayStart);

Step 7 - determine the distance of Vertex with PlaneDistance and Cross2
DistanceToPlane=DistanceToPlaneFunction(Vertex, Cross2, PlaneDistance);

Step 8 - create a vector with a length of DistanceToPlane using Cross2
Vector3=Cross2* -DistanceToPlane; //this is scalar


Step 9 - finally add Vector3 to Vertex and that should create a point that rests on the line being tested.
PointOnLine=Vertex+Vector3;


So does that look familiar? Is there a simpler way?

[edited by - WhatEver on January 18, 2003 6:46:37 PM]

Share this post


Link to post
Share on other sites
eek!! from the looks of things what you''re after is projection. Projecting vector A onto vector B gives you a vector with the length of A in the direction of B. So if A is a vector from the base of your line to your vertex, and B is your line then the projection will give you the point on the line (with the base of the line as the origin) that is nearest to your vertex.

Projection of A onto B is

A.B
C = ----- * B
|B|^2

The only thing to be careful about is that the projection works with vectors, not lines of a certain length. After doing the projection you''ll have to check that C isn''t off either end of the line.

Share this post


Link to post
Share on other sites
I can''t seem to figure out what |B|^2 is. I know |B| is suppose to be the length of the line, but I don''t know what ^2 is suppose to do.

Lets say |B| = 25. What does |B|^2 equal? 50? If it is then why not just do B*B?

Share this post


Link to post
Share on other sites
With that said the C style formula would be:

MultiplyScalar(C, B, (Dot(A, B) / Dot(B, B)));

Then to get the point out into world space on the line you would add the Origin of the Line to C.

Share this post


Link to post
Share on other sites
Whoop, 50 is suppose to be 625 .

If |B| = 25, then B*B = 625. If the formula is |B|^2, then the answer is 625 which is the same as B*B.

Pretty nifty formula :D.

[edited by - WhatEver on January 18, 2003 9:45:11 PM]

Share this post


Link to post
Share on other sites
Hey... that brings up a good question...

Projection finds the length of a direction vector projected onto a direction vector...

Is there a similar quick function for projecting a direction vector onto a plane?


... oh wait. I got it already (slaps forehead)... just project onto the normal vector and subtract from the original...


NEVERMIND!!! :o

[edited by - Nypyren on January 18, 2003 9:52:55 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by joanusdmentia
yeah, |B|^2 is |B| squared is B.B

I'm just used to seeing the formula written down in text books that use |B|^2. Although they use superscript font, btw how do you do that in the forums?


HTML is supported so you can do superscript as well as subscript

Use <sub> to start a subscript block and </sub> to end a subscript block, and likewise <sup> to start a superscript block and </sup> to end it.

So |B|2.

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edit - pesky tags - missed a closing tag ]

[edited by - s1ca on January 19, 2003 1:33:36 PM]

Share this post


Link to post
Share on other sites
Should be fairly easy:

given a line AB and a point P:

1)create Vector AB, say AB =
2)create a Vector perpendicular to AB the size of AB called AB* = OR <-y, x>.
3) Now make Vector PA
4) Project PA onto the newly created AB* using the dot product
5) to get D, divide that product by the length of AB

*done*
edit: oops you're working with 3D, so you can't use this method,here's another:
1)get a point on line AB, any point call it C
2)make a vector PC
3)project PC onto AB
4)you now have the distance from C to a point X ON AB that is right under P.
5)add this distance over a normalized vector of AB on to C to create X.
6)Make CX, the length of this vector is what you want.

I think that works

[edited by - Wicked Ewok on January 19, 2003 11:17:33 PM]

Share this post


Link to post
Share on other sites