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.h | 1 lib/src/main/cpp/test_items/park_bottom.cpp | 4 +- lib/src/main/cpp/test_items2/drive_straight.cpp | 2 lib/src/main/cpp/test_items/park_edge.cpp | 12 +++-- lib/src/main/cpp/test_items/stop_and_start.cpp | 14 +++++-- lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl | 2 lib/src/main/cpp/Geometry.cpp | 68 ++++++++++++++++++++++++++++++++++ lib/src/main/cpp/test_items/area_exam.cpp | 5 ++ lib/src/main/cpp/test_items/area_exam.h | 8 ++++ lib/src/main/cpp/CMakeLists.txt | 1 10 files changed, 104 insertions(+), 13 deletions(-) diff --git a/lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl b/lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl index 421c6f1..97da4e7 100644 --- a/lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl +++ b/lib/src/main/aidl/com/anyun/exam/lib/IListenerInterface.aidl @@ -5,7 +5,7 @@ interface IListenerInterface { /** - * 杩滅▼鏈嶅姟缁橲DK鐨勫洖璋冩秷鎭紝涓嶅澶栨彁渚涚粰APP瀹㈡埛绔� + * * Demonstrates some basic types that you can use as parameters * and return values in AIDL. */ diff --git a/lib/src/main/cpp/CMakeLists.txt b/lib/src/main/cpp/CMakeLists.txt index cb10f90..368252d 100644 --- a/lib/src/main/cpp/CMakeLists.txt +++ b/lib/src/main/cpp/CMakeLists.txt @@ -35,6 +35,7 @@ test_items/stop_and_start.cpp test_items/driving_curve.cpp test_items/turn_a90.cpp + test_items/area_exam.cpp test_items2/common_check.cpp test_items2/dummy_light.cpp 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; +} diff --git a/lib/src/main/cpp/Geometry.h b/lib/src/main/cpp/Geometry.h index 540cc87..aacdb54 100644 --- a/lib/src/main/cpp/Geometry.h +++ b/lib/src/main/cpp/Geometry.h @@ -58,5 +58,6 @@ bool OutsidePolygon(const Polygon *t1, const Polygon *t2); int IntersectionOfLine(PointF p1, PointF p2, PointF p3); PointF GetVerticalPoint(PointF p1, PointF p2, PointF p3); +PointF Calc3Point(PointF p1, PointF p2, double L, char dir); #endif //GUI_GEOMETRY_H diff --git a/lib/src/main/cpp/test_items/area_exam.cpp b/lib/src/main/cpp/test_items/area_exam.cpp new file mode 100644 index 0000000..8516dd1 --- /dev/null +++ b/lib/src/main/cpp/test_items/area_exam.cpp @@ -0,0 +1,5 @@ +// +// Created by YY on 2020/4/3. +// + +#include "area_exam.h" diff --git a/lib/src/main/cpp/test_items/area_exam.h b/lib/src/main/cpp/test_items/area_exam.h new file mode 100644 index 0000000..a562acf --- /dev/null +++ b/lib/src/main/cpp/test_items/area_exam.h @@ -0,0 +1,8 @@ +// +// Created by YY on 2020/4/3. +// + +#ifndef MYAPPLICATION2_AREA_EXAM_H +#define MYAPPLICATION2_AREA_EXAM_H + +#endif //MYAPPLICATION2_AREA_EXAM_H diff --git a/lib/src/main/cpp/test_items/park_bottom.cpp b/lib/src/main/cpp/test_items/park_bottom.cpp index 3a59252..e200125 100644 --- a/lib/src/main/cpp/test_items/park_bottom.cpp +++ b/lib/src/main/cpp/test_items/park_bottom.cpp @@ -90,7 +90,7 @@ if (CrashRedLine(map, car, who)) { - if (!occurCrashRedLine) { + if (!occurCrashRedLine && reverseCar) { occurCrashRedLine = true; // 杞﹁韩鍑虹嚎锛屼笉鍚堟牸 AddExamFault(7, rtkTime); @@ -157,7 +157,7 @@ if (moveDirect == storeMoveDirectBeforeStop) { // 鍚屾柟鍚戝啀鍚姩锛岀户缁垽鏂槸鍚﹀仠杞﹁秴鏃� - if (tp - stopTimepoint >= STOP_CAR_TIME) { + if (tp - stopTimepoint >= STOP_CAR_TIME && reverseCar) { // 鍋滆溅瓒�2绉掞紝姣忔鎵�5鍒� AddExamFault(11, rtkTime); DEBUG("涓�斿仠杞�"); diff --git a/lib/src/main/cpp/test_items/park_edge.cpp b/lib/src/main/cpp/test_items/park_edge.cpp index 921ce34..6836600 100644 --- a/lib/src/main/cpp/test_items/park_edge.cpp +++ b/lib/src/main/cpp/test_items/park_edge.cpp @@ -54,6 +54,8 @@ parkSuccess = false; parkStatus = 0; occurMoveBack = false; + + // 浠呭綋鍙戠敓鍊掕溅锛屾墠鎰忓懗鐫�椤圭洰寮�濮� if (moveStatus == -1) { occurMoveBack = true; moveBackTimePoint = TimeMakeComposite(rtkTime->hh, rtkTime->mm, rtkTime->ss, rtkTime->mss*10); @@ -63,23 +65,23 @@ int TestParkEdge(const Polygon *map, const car_model *car, const car_model *carPrev, double speed, int moveStatus, const struct RtkTime *rtkTime) { if (CrashRedLine1(map, car)) { - if (!occurCrashRedLine1) { + if (!occurCrashRedLine1 && occurMoveBack) { // 杞﹁疆鍘嬭竟绾匡紝姣忔鎵�10鍒� AddExamFault(23, rtkTime); DEBUG("杞﹁疆鍘嬭竟绾�"); + occurCrashRedLine1 = true; } - occurCrashRedLine1 = true; } else { occurCrashRedLine1 = false; } if (CrashRedLine2(map, car)) { - if (!occurCrashRedLine2) { + if (!occurCrashRedLine2 && occurMoveBack) { // 杞﹁韩鍘嬪簱浣嶇嚎锛屾瘡娆℃墸10鍒� AddExamFault(24, rtkTime); DEBUG("杞﹁韩鍘嬪簱浣嶇嚎"); + occurCrashRedLine2 = true; } - occurCrashRedLine2 = true; } else { occurCrashRedLine2 = false; } @@ -121,7 +123,7 @@ if (moveStatus == storeMoveStatusBeforeStop) { // 鍚屾柟鍚戝啀鍚姩锛岀户缁垽鏂槸鍚﹀仠杞﹁秴鏃� - if (tp - stopTimepoint >= STOP_CAR_TIME) { + if (tp - stopTimepoint >= STOP_CAR_TIME && occurMoveBack) { // 鍋滆溅瓒�2绉掞紝姣忔鎵�5鍒� AddExamFault(26, rtkTime); DEBUG("鍋滆溅瓒呮椂"); diff --git a/lib/src/main/cpp/test_items/stop_and_start.cpp b/lib/src/main/cpp/test_items/stop_and_start.cpp index b57ceec..3b904d6 100644 --- a/lib/src/main/cpp/test_items/stop_and_start.cpp +++ b/lib/src/main/cpp/test_items/stop_and_start.cpp @@ -90,7 +90,7 @@ { double dis2 = DistanceOfTire2Edge(map, car); - MA_SendDistance(-1, dis2); + MA_SendDistance(DistanceOf(map->point[8], map->point[7]) - dis2, dis2); } if (prevMoveDirect != moveDirect) { @@ -262,7 +262,13 @@ // 鍏ㄨ溅閮介渶涓嶅湪鍦板浘涓� bool ret = false; - Polygon carBody; + Polygon carBody, map2; + PointF vPoint = Calc3Point(map->point[8], map->point[0], DistanceOf(map->point[8], map->point[7]), 'R'); + + map2.num = 4; + map2.point = (PointF *)malloc(map2.num * sizeof(PointF)); + + MakePolygon(&map2, {vPoint, map->point[0], map->point[7], map->point[8]}); carBody.num = car->bodyNum; carBody.point = (PointF *)malloc(carBody.num * sizeof(PointF)); @@ -270,11 +276,11 @@ carBody.point[i] = car->carXY[car->body[i]]; } - if (IntersectionOf(&carBody, map) == GM_None) { + if (IntersectionOf(&carBody, &map2) == GM_None) { ret = true; } free(carBody.point); - + free(map2.point); return ret; } diff --git a/lib/src/main/cpp/test_items2/drive_straight.cpp b/lib/src/main/cpp/test_items2/drive_straight.cpp index 8db23e0..5e2b12f 100644 --- a/lib/src/main/cpp/test_items2/drive_straight.cpp +++ b/lib/src/main/cpp/test_items2/drive_straight.cpp @@ -49,7 +49,7 @@ double l2 = DistanceOf(car->carXY[car->right_rear_tire[TIRE_OUTSIDE]], road_edge); - MA_SendDistance(-1, (l1+l2)/2.0); + MA_SendDistance(6 - (l1+l2)/2.0, (l1+l2)/2.0); } if (!crossStartLine) { -- Gitblit v1.8.0