Slide 51
Slide 51 text
Advice
For selecting a line, consider something like this, then if the
distance is "small" you can consider the line clicked (selected)
// calculates the distance from P3(x3,y3)
// to the line defined by P1(x1,y1) and P2(x2,y2)
public static double distance
(int x1, int y1, int x2, int y2, int x3, int y3) {
double A = y2 - y1;
double B = x1 - x2;
double C = x2 * y1 - x1 * y2;
double distance = Math.abs(A * x3 + B * y3 + C) / Math.sqrt(A * A + B * B);
return distance;
}
51