summaryrefslogtreecommitdiff
path: root/geometry
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2016-12-13 23:59:33 +0100
committerPaul Jungeblut <paul.jungeblut@gmail.com>2016-12-13 23:59:33 +0100
commit1cbe65cd82fa4d9adeda37f5a125ac617cc2f066 (patch)
tree972b1d7235c6edd631f83f8f28e006ca9baa5b71 /geometry
parenta64f52d0086473c54291cd125e787ef52ff93983 (diff)
Small changes.
Diffstat (limited to 'geometry')
-rw-r--r--geometry/formulars.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/geometry/formulars.cpp b/geometry/formulars.cpp
index c1010ff..3a5e53b 100644
--- a/geometry/formulars.cpp
+++ b/geometry/formulars.cpp
@@ -93,7 +93,7 @@ double distToLine(pt a, pt b, pt p) {
// Liegt p auf der Geraden a-b?
bool pointOnLine(pt a, pt b, pt p) {
- return orientation(a, b, c) == 0;
+ return orientation(a, b, p) == 0;
}
// Liegt p auf der Strecke a-b?
@@ -108,15 +108,15 @@ bool pointOnLineSegment(pt a, pt b, pt p) {
// Entfernung von Punkt p zur Strecke a-b.
double distToSegment(pt a, pt b, pt p) {
if (a == b) return abs(p - a);
- double segLength = abs(a - b);
- double u = ((real(p) - real(a)) * (real(b) - real(a)) +
- (imag(p) - imag(a)) * (imag(b) - imag(a))) /
- (segLength * segLength);
- pt projection(real(a) + u * (real(b) - real(a)),
- imag(a) + u * (imag(b) - imag(a)));
- double projectionDist = abs(p - projection);
- if (!pointOnLineSegment(a, b, projection)) projectionDist = 1e30;
- return min(projectionDist, min(abs(p - a), abs(p - b)));
+ double segLength = abs(a - b);
+ double u = ((real(p) - real(a)) * (real(b) - real(a)) +
+ (imag(p) - imag(a)) * (imag(b) - imag(a))) /
+ (segLength * segLength);
+ pt projection(real(a) + u * (real(b) - real(a)),
+ imag(a) + u * (imag(b) - imag(a)));
+ double projectionDist = abs(p - projection);
+ if (!pointOnLineSegment(a, b, projection)) projectionDist = 1e30;
+ return min(projectionDist, min(abs(p - a), abs(p - b)));
}
// Kürzeste Entfernung zwischen den Strecken a-b und c-d.