summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/geometry/lines.cpp16
-rw-r--r--content/geometry/linesAndSegments.cpp2
2 files changed, 9 insertions, 9 deletions
diff --git a/content/geometry/lines.cpp b/content/geometry/lines.cpp
index 95536a4..36de1db 100644
--- a/content/geometry/lines.cpp
+++ b/content/geometry/lines.cpp
@@ -1,10 +1,10 @@
struct line {
- double a, b, c; // ax + by + c = 0; vertikale Line: b = 0, sonst: b = 1
- line(pt p, pt q) : a(-imag(q-p)), b(real(q-p)), c(cross({b, -a},p)) {}
+ double a, b, c; // ax + by + c = 0; vertikale Gerade: b = 0
+ line(pt p, pt q) : a(imag(p-q)), b(real(q-p)), c(cross({-b, a}, p)) {}
};
-line pointsToLine(pt p1, pt p2) {
- line l;
+line pointsToLine(pt p1, pt p2) { // vertikale Gerade: b = 1 oder b = 0
+ line l(0, 0);
if (abs(real(p1 - p2)) < EPS) {
l.a = 1; l.b = 0.0; l.c = -real(p1);
} else {
@@ -15,19 +15,19 @@ line pointsToLine(pt p1, pt p2) {
return l;
}
-bool parallel(line l1, line l2) {
+bool parallel(line l1, line l2) { // braucht b in {0, 1}
return (abs(l1.a - l2.a) < EPS) && (abs(l1.b - l2.b) < EPS);
}
-bool same(line l1, line l2) {
+bool same(line l1, line l2) { // braucht b in {0, 1}
return parallel(l1, l2) && (abs(l1.c - l2.c) < EPS);
}
-bool intersect(line l1, line l2, pt& p) {
+bool intersect(line l1, line l2, pt& res) { // braucht b in {0, 1}
if (parallel(l1, l2)) return false;
double y, x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
if (abs(l1.b) > EPS) y = -(l1.a * x + l1.c);
else y = -(l2.a * x + l2.c);
- p = {x, y};
+ res = {x, y};
return true;
}
diff --git a/content/geometry/linesAndSegments.cpp b/content/geometry/linesAndSegments.cpp
index 1e21cba..ddab554 100644
--- a/content/geometry/linesAndSegments.cpp
+++ b/content/geometry/linesAndSegments.cpp
@@ -5,7 +5,7 @@ bool pointOnLine(pt a, pt b, pt p) {
// Test auf Linienschnitt zwischen a-b und c-d. (nicht identisch)
bool lineIntersection(pt a, pt b, pt c, pt d) {
- return abs(cross(a - b, c - d)) < EPS;
+ return abs(cross(a - b, c - d)) > EPS;
}
// Berechnet den Schnittpunkt der Graden a-b und c-d.