回答編集履歴
1
始点が別にあることを見落としていたので修正
test
CHANGED
@@ -12,6 +12,8 @@
|
|
12
12
|
|
13
13
|
int x2 = 200, y2 = 200;
|
14
14
|
|
15
|
+
int x3 = 150, y3 = 150;
|
16
|
+
|
15
17
|
int addTheta = 60;
|
16
18
|
|
17
19
|
double length = Math.hypot(x2 - x1, y2 - y1);
|
@@ -20,11 +22,11 @@
|
|
20
22
|
|
21
23
|
theta += Math.toRadians(addTheta);
|
22
24
|
|
23
|
-
int x
|
25
|
+
int x4 = (int)(length * Math.cos(theta) + x3);
|
24
26
|
|
25
|
-
int y
|
27
|
+
int y4 = (int)(length * Math.sin(theta) + y3);
|
26
28
|
|
27
|
-
g.drawLine(x
|
29
|
+
g.drawLine(x3, y3, x4, y4);
|
28
30
|
|
29
31
|
```
|
30
32
|
|
@@ -38,15 +40,17 @@
|
|
38
40
|
|
39
41
|
int x2 = 200, y2 = 200;
|
40
42
|
|
43
|
+
int x3 = 150, y3 = 150;
|
44
|
+
|
41
45
|
int addTheta = 60;
|
42
46
|
|
43
47
|
double rad = Math.toRadians(addTheta);
|
44
48
|
|
45
|
-
int x
|
49
|
+
int x4 = (int)((x2 - x1) * Math.cos(rad) - (y2 - y1) * Math.sin(rad) + x3);
|
46
50
|
|
47
|
-
int y
|
51
|
+
int y4 = (int)((x2 - x1) * Math.sin(rad) + (y2 - y1) * Math.cos(rad) + y3);
|
48
52
|
|
49
|
-
g.drawLine(x
|
53
|
+
g.drawLine(x3, y3, x4, y4);
|
50
54
|
|
51
55
|
```
|
52
56
|
|