Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Right angle formula

  1. Dec 30, 2004 #1
    okay, I looked around in google and I'm not getting what I need. What is the formula to prove if two intersecting lines create a right angle or not? Having Cartesian coordinates only.
  2. jcsd
  3. Dec 30, 2004 #2


    User Avatar
    Homework Helper

    There are a couple of ways to do it. The first that occurs to me is to look at the slopes. What do you know about the slopes of perpendicular lines?
  4. Dec 30, 2004 #3
    negative reciprocal, however, if the slope of a coordinate was 0, then the reciprocal of that would be undefined
  5. Dec 30, 2004 #4


    User Avatar
    Homework Helper

    Sorry to be picky, but a "coordinate" has no slope.

    If the slope of a line is 0, what does that tell you about the line? What if the slope of the line is undefined? And how are those two lines related?
  6. Dec 30, 2004 #5
    you see, I'm writing a Java program, and I would give me a divide by zero error if I tried to find the slope that was vertical. But I have an idea, I would just say that if the 2 x's are equal, then skip to find the slope of the second line. If the slope of that line is zero, then it creates a right angle.

    thanks for the help
  7. Dec 30, 2004 #6


    User Avatar
    Homework Helper

    You're welcome, and your idea will work just fine. I've used that many times. :)
  8. Dec 31, 2004 #7


    User Avatar
    Science Advisor
    Homework Helper

    You could test the dot product. If zero, the lines are perpendicular.

    The dot product is just a variation on the cosine difference identity.

    [tex]\frac{x_1 * x_2 + y_1 * y_2+ z_1 * z_2}{v_1*v_2} = cos \theta[/tex]

    with [tex]\theta[/tex] being the angle between the two lines.
    The denominator of the left hand side is the product of the norms of the two vectors. If you only need to find out whether the lines are perpendicular, you don't even need to worry about the denominator.
    The x_1, y_1, z_1, etc. are Cartesian coordinates for the vector (v_1, etc)
    The cosine of a 90 degree angle is zero.

    If you're only working in two dimensions, just leave the z's out (z_1 and z_2 are both equal to zero when working in two dimensions)
  9. Jan 1, 2005 #8
    say your 2 lines are represented by 2 equations.

    [tex] y=m_1 x + b_1 [/tex]

    [tex] y=m_2 x + b_2 [/tex]

    the slope [tex]m_1= \frac{y_1}{x_1}[/tex]
    and the same goes for [itex]m_2[/itex]

    if [tex] x_1x_2+y_1y_2=0[/tex] then the lines are perpendicular.

    the only case where there's a problem is when one of your lines is zero. However in that case if the slope of the other line is anything but undefined then it's obvious it isn't perpendicular.

    If your question was finding a perpendicular line given the first then the negative reciprocal of the slope should suit you fine.
  10. Jan 1, 2005 #9
    Bob's vector method may look overly complicated for this one but it is the most attractive one and atleast needs to be practiced if one is into programming. Higher level graphics development depends largely on vector methods and their matrix representations.

    -- AI
  11. Jan 1, 2005 #10
    Hi UrbanXrisis

    If you are writing a method in Java to do this calculation, I think you should use the fact that the ratio of the gradients of two intersecting lines is negative if the lines are perpendicular to each other.

    If you have your Cartesian coordinates, you can obtain both gradients, but your method will need to have some special circumstances, like: -

    1. if one of the lines have a gradient of infinity (vertical line), then the lines will be perpendicular if the other line has nought gradient.

    ....however, you will have other special circumstances if you write your Java method this way. I've thought of one way which might be helpful to you.

    If you know that the ratio of the gradients of 2 perpendicular lines is negative, you will quickly notice that the absolute values of the two gradients should be equal !!

    If line L1 (gradient = m1) is perpendicular to line L2 (gradient = m2), then m1/m2 = -1 and |m1| = |m2|. So, you can test the equality of the absolute values of the gradients first. If they match, you can test whether one of them is negative, and if one of them is negative, the lines are perpendicular.

    There is a built-in function in Java which you can use to determine the absolute values of a real number: -
    Code (Text):
  12. Jan 1, 2005 #11
    Damn I didn't think about that.

    If you multiply m1 by m2 and get -1 then your lines are perpendicular.
  13. Jan 1, 2005 #12
    If m1 = 0, what is m2? and does m1*m2=-1 help. Read the above few post, where the author of the post has raised this question.

    The formula u derived earlier was much better than this (as far as computational overhead is concerned), can u see why? Your earlier formula is closely related even to the vector method and i could even say the results are identical.

    Ameed Khan,
    Think again , it should m1m2 = -1 and not m1/m2 = -1.

    -- AI
  14. Jan 2, 2005 #13
    All my apologies. I made a mistake in the formula, and consequently, the explanation became totally untrue. You are right TenaliRaman, the formula should be : -
    (m1)*(m2) = -1

    I had this in my head, but my mind was quicker than my hands, so I mistyped the formula. My apologies for that.
  15. Jan 3, 2005 #14
    Its ok! I have written 3*4=7 many times , so u are doing really good!

    -- AI
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook