Results 1 to 4 of 4
Thread: Perpendicular??
- 11-09-2010, 11:21 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
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?
- 11-09-2010, 11:29 PM #2
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Hi Moondrop,
I am no expert at this but you could consider to check whether they almost match:
Hope this helps.Java Code:if ((m1 - 1.0 / m2) < precision) { System.out.println("The lines are perpendicular."); }
ErikI'm new to Java but I like to help where ever I can. :)
- 11-09-2010, 11:55 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Thank you. :) I finally got it.
-
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)


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks