直角坐標系用三角函數判斷旋轉方向和旋轉角度


坐標原點知道

兩個點知道

相對於坐標原點的旋轉的角度可以通過三角函數算出來

因為知道了三個邊的長度,

Math.acos((bb*bb+cc*cc-aa*aa)/(2*bb*cc))
主要就是這個方法
至於旋轉x1*y2-x2*y1大於0就是順時針,小於0就是逆時針,考慮原點的位置
 1 public class DirectionClass {
 2 
 3     public double x0=LambdaTest01.InterSectionLat;
 4     public double y0=LambdaTest01.InterSectionLng;
 5     
 6     //給定兩個點的方向,判斷怎么轉向的
 7     //首先確定大方向就是用路口的定點作為基准點,兩個點作為偏置點,制作到一個三角形然后用三個邊判斷兩個點的角度。關鍵是如何判斷順時針還是逆時針。
 8     public static double directionTurned(double x1,double y1,double x2,double y2) {
 9         double result=0;
10         double bb=lengthConvert.getDistance(x1, y1, LambdaTest01.InterSectionLat, LambdaTest01.InterSectionLng);
11         double cc=lengthConvert.getDistance(x2, y2, LambdaTest01.InterSectionLat, LambdaTest01.InterSectionLng);
12         double aa=lengthConvert.getDistance(x1, y1, x2, y2);
13         result=Math.acos((bb*bb+cc*cc-aa*aa)/(2*bb*cc));
14         double fix=180/Math.PI;
15         return result*fix;
16     }
17     public static double directionTurned_bd(double x1,double y1,double x2,double y2) {
18         double result=0;
19         double bb=lengthConvert.getDistance(x1, y1, LambdaTest01.testInterSectionLat, LambdaTest01.testInterSectionLng);
20         double cc=lengthConvert.getDistance(x2, y2, LambdaTest01.testInterSectionLat, LambdaTest01.testInterSectionLng);
21         double aa=lengthConvert.getDistance(x1, y1, x2, y2);
22         result=Math.acos((bb*bb+cc*cc-aa*aa)/(2*bb*cc));
23         double fix=180/Math.PI;
24         return result*fix;
25     }
26     public static double directionTurned2(double x1,double y1,double x2,double y2) {
27         double result=0;
28         double bb=lengthConvert.getDistance2(x1, y1, 0, 0);
29         double cc=lengthConvert.getDistance2(x2, y2, 0, 0);
30         double aa=lengthConvert.getDistance2(x1, y1, x2, y2);
31         System.out.println(bb);
32         System.out.println(cc);
33         System.out.println(aa);
34         double fix=180/Math.PI;
35         result=Math.acos((bb*bb+cc*cc-aa*aa)/(2*bb*cc));
36         return result*fix;
37     }
38     public static boolean wise_anti(double x1,double y1,double x2,double y2) {
39         double result=(x1-LambdaTest01.InterSectionLat)*(y2-LambdaTest01.InterSectionLng)-(x2-LambdaTest01.InterSectionLat)*(y1-LambdaTest01.InterSectionLng);
40         if (result>=0) {
41             System.out.println("順時針");
42             return true;
43         }else {
44             System.out.println("逆時針");
45             return false;    
46         }
47     }
48     public static boolean wise_anti_bd(double x1,double y1,double x2,double y2) {
49         double result=(x1-LambdaTest01.testInterSectionLat)*(y2-LambdaTest01.testInterSectionLng)-(x2-LambdaTest01.testInterSectionLat)*(y1-LambdaTest01.testInterSectionLng);
50         if (result>=0) {
51             System.out.println("順時針");
52             return true;
53         }else {
54             System.out.println("逆時針");
55             return false;    
56         }
57     }
58     
59     
60     public static void main(String[] args) {
61         // TODO Auto-generated method stub
62 
63         double result=directionTurned2(1, 0, 0, 1);
64         System.out.println(result);
65     }
66 
67 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM