Занятие 13. Точки, прямые, отрезки. Справочник

Точки, прямые, отрезки Справочник

Классы точки и прямой

public class pt 
{
 	double x, y;
 	public pt(double x, double y) 
	{
		this.x = x;
		this.y = y;
	}
	//…
}
class line 
{
	double a, b, c;
	public line(double a, double b, double c) 
	{
		this.a = a;
		this.b = b;
		this c = c;
	}
        //…
}
Косое произведение векторов (a, b) и (c,d)

double det (double a, double b, double c, double d) 
{
	return a * d - b * c;
}
Взаиморасположение прямых

static final double EPS = 1e-9;
//null if no points
pt intersect (line m, line n) 
{
	double zn = det (m.a, m.b, n.a, n.b);
	if (abs (zn) < EPS)
		return null;
	return new pt (- det (m.c, m.b, n.c, n.b) / zn,
			     - det (m.a, m.c, n.a, n.c) / zn);
	
}
boolean parallel (line m, line n) {
	return Math.abs (det (m.a, m.b, n.a, n.b)) < EPS;
}
 
boolean equivalent (line m, line n) {
	return Math.abs (det (m.a, m.b, n.a, n.b)) < EPS
		&& Math.abs (det (m.a, m.c, n.a, n.c)) < EPS
		&& Math.abs (det (m.b, m.c, n.b, n.c)) < EPS;
}