geometry2D.cpp
Go to the documentation of this file.00001
00015 #include <dlrNumeric/geometry2D.h>
00016 #include <dlrNumeric/utilities.h>
00017
00018 namespace dlr {
00019
00020 namespace numeric {
00021
00022 bool
00023 bilaterate(const Vector2D& point0, const Vector2D& point1,
00024 double range0, double range1,
00025 Vector2D& intersection0, Vector2D& intersection1)
00026 {
00027
00028
00029
00030
00031
00032 Vector2D baselineVector(point1 - point0);
00033
00034
00035
00036 double x0 = magnitude(baselineVector);
00037
00038
00039 Vector2D e0(baselineVector / x0);
00040 Vector2D e1(-e0.y(), e0.x());
00041
00042
00043
00044
00045
00046
00047 double r0Squared = range0 * range0;
00048 double xValue = (r0Squared - range1 * range1 + x0 * x0) / (2 * x0);
00049
00050
00051 double r0SquaredMinusXSquared = r0Squared - xValue * xValue;
00052 if(r0SquaredMinusXSquared < 0.0) {
00053 return false;
00054 }
00055 double yValue = std::sqrt(r0SquaredMinusXSquared);
00056
00057
00058 Vector2D xComponent = xValue * e0;
00059 Vector2D yComponent = yValue * e1;
00060 intersection0 = point0 + xComponent + yComponent;
00061 intersection1 = point0 + xComponent - yComponent;
00062 return true;
00063 }
00064
00065 }
00066
00067 }