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

Started by
12 comments, last by WhatEver 21 years, 3 months ago
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!
Advertisement
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 --
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]
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.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
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?
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.
I''m pretty sure it means to the power of, or in this case squared.
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]
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]
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?
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V

This topic is closed to new replies.

Advertisement