I am working on a computational geometry projects which contains classes for Point, Line, Triangle, etc. I store lines as a yint and a slope, however this is giving me issues with vertical lines, as shown in the issue below. I have to maintain the usage of slopes generally, however I could do a conversion to degrees if you feel this is appropriate for the situation.
Below is a method to get an array of all of the altitudes of a triangle, implemented in the triangle class. It does not work. I am pretty sure it is due to infinite slopes, but not entirely. Any ideas?
//sides is an array of LineSegs {AB, BC, CA}
public Line[] getLineAltitudes() {
Line[] returner = new Line[3];
for (int i=0; i<3; i++) {
//decides which point is opposite to lineseg
int pointgot = 0;
if (i == 0) pointgot = 2;
else if (i == 1) pointgot = 0;
else pointgot = 1;
//gets the perpendicular to a side
Double newSlope = (double)1/sides[i].getSlope();
System.out.println(newSlope);
if (newSlope.isInfinite()) newSlope = (double) 0;
//constructs a line using the (working) constructor Line(point on line, slope)
returner[i] = new Line(getPoints()[pointgot],newSlope);
}
return returner;
}