From 7ad5b81283c39e66ba2ca84314e283f277fc77e0 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期五, 03 四月 2020 11:39:17 +0800 Subject: [PATCH] 坐标 --- lib/src/main/cpp/Geometry.cpp | 68 ++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 0 deletions(-) diff --git a/lib/src/main/cpp/Geometry.cpp b/lib/src/main/cpp/Geometry.cpp index 01e15cd..0a43ae1 100644 --- a/lib/src/main/cpp/Geometry.cpp +++ b/lib/src/main/cpp/Geometry.cpp @@ -10,6 +10,7 @@ #include <jni.h> #include <malloc.h> #include <initializer_list> +#include <cctype> #include "jni_log.h" @@ -474,3 +475,70 @@ return p4; } + +/**************************************************************** + * p3 + * | 'L' + * | + * p1------------------>p2 + * | + * | 'R' + * p3 + * @param p1 + * @param p2 + * @param L + * @param dir + * @return + */ +PointF Calc3Point(PointF p1, PointF p2, double L, char dir) +{ + PointF p3; + + dir = toupper(dir); + + if (dir != 'L' && dir != 'R') + dir = 'L'; + + if (isEqual(p1.X, p2.X)) { + p3.Y = p2.Y; + if (p2.Y > p1.Y) { + p3.X = p2.X + ((dir == 'L')? -L:L); + } else { + p3.X = p2.X + ((dir=='L')?L:-L); + } + return p3; + } + if (isEqual(p1.Y, p2.Y)) { + p3.X = p2.X; + if (p2.X > p1.X) { + p3.Y = p2.Y + ((dir == 'L')? L:-L); + } else { + p3.Y = p2.Y + ((dir == 'L')? -L:L); + } + return p3; + } + + double k = (p2.Y - p1.Y) / (p2.X - p1.X); + double b = p1.Y - k*p1.X; + + double A = 1 + pow(k, 2); + double B = 2*k*(b - p2.Y) - 2*p2.X; + double C = pow(b - p2.Y, 2) + pow(p2.X, 2) - pow(L,2); + + double x3, y3; + + + if (p1.X < p2.X) { + x3 = (- B - sqrt(pow(B, 2) - 4*A*C))/(2*A); + } else { + x3 = (- B + sqrt(pow(B, 2) - 4*A*C))/(2*A); + } + y3 = k * x3 + b; + + p3.X = x3; + p3.Y = y3; + + p3 = rotatePoint(p3, p2, (dir == 'L') ? 270 : 90); + + return p3; +} -- Gitblit v1.8.0