UrbanXrisis said:
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
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: -