Math stumper

This is a discussion on Math stumper within the C++ Programming forums, part of the General Programming Boards category; Here's a little math problem for yall. I need to find out how to get a perpenticular line from a ...

  1. #1
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215

    Math stumper

    Here's a little math problem for yall. I need to find out how to get a perpenticular line from a given line in 3D Space. So for example: (2x, 0y, 4z) --- (4x, 0y, 4z)...how would you find the line perpendicular to that one at either of those points? What if the line was diagonal? (2x, 0y, 4z) --- (8x, 2y, 3z)?
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    I'm not sure how you would get a 3D perpendicular. Would that be a line that somehow creates right angles to the other line from every possible direction from the intersection?

    Think of a three demensional plane. Are you considering the X and Y axis to be perpendicular or the Y and Z axis?
    Sent from my iPadŽ

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,075
    I guess I would say, do it the same way you do a two demensional line. Get the slopes of the three dimensional line and get the negetive reciprocals.

    Edit: Here is some interesting stuff I found.
    http://mathforum.org/library/drmath/view/53036.html
    Last edited by SlyMaelstrom; 11-07-2005 at 03:57 AM.
    Sent from my iPadŽ

  4. #4
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Ok, think of this... | = plane --> = plane normal X = Position I need to find

    |X
    |
    |------->
    |
    |X

    How would I find X from the plane normal if the normal is thought to be in the direct center of the plane. For this example, adding or subtracting from the y value would be the answer, but what if the plane is diagonal? You would have to add/subtract from x, y, & z to get a correct perpenticular point.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  5. #5
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    I can tell you how to check if 2 lines are perpendicular:

    If line 1 is a, and line 2 is b then to check you need to know the eqn:

    a.b =|a||b|cos(theta)

    where theta is the angle between them, but if they are perpendicular then theta = 0, so basically a.b = 0 where a.b is the scalar product.

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    At a given point in 3 Space there are infintely many perpendicular lines. So the question becomes which one do you want?

    If you just want any perpendicular line then you can use vectors to get one. Just take the vector between your two points [ex: (2x, 0y, 4z) --- (4x, 0y, 4z) gives the vector (2, 0, 0)] and cross it with any other vector [lets go with (1,0,0)]. That'll give you a vector that is orthogonal to both vectors. From that you can derive the equation of the line.

    Ok, think of this... | = plane --> = plane normal X = Position I need to find

    |X
    |
    |------->
    |
    |X

    How would I find X from the plane normal if the normal is thought to be in the direct center of the plane. For this example, adding or subtracting from the y value would be the answer, but what if the plane is diagonal? You would have to add/subtract from x, y, & z to get a correct perpenticular point.
    Ok so we know that Ax + By + Cz + D = 0 is the standard equation for a plane. Given that we know that the vector (A, B, C) is the normal vector for the plane.

    However your picture makes little sense when applied to an actual plane since there are infinatly many directions you can go from any point on that plane. So the questioin would be which direction do you want to go?

    Of assistance might be the distance formula:
    d = sqrt ( x^2 + y^2 + z^2 )

  7. #7
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Very helpful Thantos, exactly what I was looking for. I have a couple questions about this psuedocode, this is a diagonal line:

    Code:
    Vec3 start = (0.0, 0.0, 0.0);
    end = (5.0, 4.0, 5.0);
    Vec3 DirUp;
    
    if( end >=start )
        DirUp = end-start;
    else
        DirUp = start-end;
    
    Vec3 theCross = (1.0, 0.0, 0.0);  // Would this always work???
    
    Vec3 Axis1 = CrossProduct(DirUp, theCross);  // Perpendicular to DirUp and theCross..great
    Now I'm lost at what to do next. I need 4 points to come out of the endpoints like an X, to form a bounding box around the line. If I could get a vector that's say 2 units away from the endpoint(perpendicular) I could get the values. Could I just multiply the normalized vector by 2.0? How could I move a point along Axis1?
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  8. #8
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Can I ask, is this for programming use in OpenGL or some kind of graphics library?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  9. #9
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    Its going to be put in DirectX for a networking application. Then when we cross platforms it's going to be in OpenGL.
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Math
    By knightjp in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 04-01-2009, 06:36 PM
  2. Help with C++ Math
    By aonic in forum C++ Programming
    Replies: 4
    Last Post: 01-29-2005, 04:40 AM
  3. Basic Math Problem. Undefined Math Functions
    By gsoft in forum C Programming
    Replies: 1
    Last Post: 12-28-2004, 03:14 AM
  4. Math Header?
    By Rune Hunter in forum C++ Programming
    Replies: 26
    Last Post: 09-17-2004, 07:39 AM
  5. toughest math course
    By axon in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-28-2003, 10:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21