#### Archived

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

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

This topic is 5634 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 RayStartVector2=Vertex-RayEnd;Step 3 - create a vector perpendicular to Vector1 and Vector2Cross1=CrossFunction(Vector2, Vector1);Step 4 - create a vector perpendicular to Cross1 and Vector1Cross2=CrossFunction(Vector1, Cross1);Step 5 - normalize Cross2NormalizeFunction(Cross2);Step 6 - determine plane distance using Cross2 and RayStartPlaneDistance=DistanceFunction(Cross2, RayStart);Step 7 - determine the distance of Vertex with PlaneDistance and Cross2DistanceToPlane=DistanceToPlaneFunction(Vertex, Cross2, PlaneDistance);Step 8 - create a vector with a length of DistanceToPlane using Cross2Vector3=Cross2* -DistanceToPlane; //this is scalarStep 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 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 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 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 on other sites
I''m pretty sure it means to the power of, or in this case squared.

##### 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 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 on other sites
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?

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×