| | |
| | | #include <jni.h> |
| | | #include <malloc.h> |
| | | #include <initializer_list> |
| | | #include <cctype> |
| | | |
| | | #include "jni_log.h" |
| | | |
| | |
| | | |
| | | 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; |
| | | } |