Results 1 to 4 of 4

Thread: Perpendicular??

  1. #1
    Moondrop is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default Perpendicular??

    Hi, how would I get the computer to tell me if two lines are perpendicular?

    This is the first part of the if-statement I'm using to tell if they are:
    if (m1 == 1.0 / m2 )
    System.out.println("The lines are perpendicular.");

    I know division sometimes causes problems with decimals.
    Can anyone help me correct this?

  2. #2
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Hi Moondrop,

    I am no expert at this but you could consider to check whether they almost match:

    Java Code:
    if ((m1 - 1.0 / m2) < precision) {
        System.out.println("The lines are perpendicular.");
    }
    Hope this helps.
    Erik
    I'm new to Java but I like to help where ever I can. :)

  3. #3
    Moondrop is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Thank you. :) I finally got it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    A slope is perpendicular to another if it is the negative inverse of the other. Also, since you don't know if the math error is positive or negative, then closer perhaps is if you do,

    (Math.abs(m1 + 1.0/m2) < precision)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •