Занятие 13. Точки, прямые, отрезки. Справочник
Сайт: | Информатикс |
Курс: | Фирма "1С". "Алгоритмы. Олимпиадное программирование на языке Java для школьников" |
Книга: | Занятие 13. Точки, прямые, отрезки. Справочник |
Напечатано:: | Гость |
Дата: | Пятница, 18 Июль 2025, 08:08 |
Точки, прямые, отрезки Справочник
Классы точки и прямой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; }
Точки, прямые, отрезки Справочник
Классы точки и прямой 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)
static 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 static Point intersect (Line m, Line n) { double zn = det (m.a, m.b, n.a, n.b); if (abs (zn) < EPS) return null; return new Point (- 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; }