1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.awt.Graphics;
public class Scissors1 {
private final int radius = 10;
private final int diameter = radius*2;
private final int bladeLength = 30;
private int leftHandleX = 100;
private int leftHandleY = 200;
private int rightHandleX = 100+diameter;
private int rightHandleY = 200;
private int leftBladeStartX = leftHandleX + diameter;
private int leftBladeStartY = leftHandleY + radius;
private int leftBladeEndX = 100+diameter;
private int leftBladeEndY = 100;
private int rightBladeStartX = rightHandleX;
private int rightBladeStartY = rightHandleY + radius;
private int rightBladeEndX = 100+diameter;
private int rightBladeEndY = 100;
public int getLeftBladeStartX() {
System.out.println(leftHandleX + " " + leftBladeStartX);
return leftBladeStartX;
}
public int getLeftBladeStartY() {
System.out.println(leftHandleY + " " + leftBladeStartY);
return leftBladeStartY;
}
public int getLeftBladeEndX() {
return leftBladeEndX;
}
public int getLeftBladeEndY() {
return leftBladeEndY;
}
public int getRightBladeStartX() {
return rightBladeStartX;
}
public int getRightBladeStartY() {
return rightBladeStartY;
}
public int getRightBladeEndX() {
return rightBladeEndX;
}
public int getRightBladeEndY() {
return rightBladeEndY;
}
public int getBladeLength() {
return bladeLength;
}
public int getDiameter() {
return diameter;
}
public int getRadius() {
return radius;
}
public int getLeftHandleX() {
return leftHandleX;
}
public int getLeftHandleY() {
return leftHandleY;
}
public int getRightHandleX() {
return rightHandleX;
}
public int getRightHandleY() {
return rightHandleY;
}
public void moveLeftHandle(int x, int y) {
int oldLeftHandleX = this.leftHandleX;
int oldLeftHandleY = this.leftHandleY;
this.leftHandleX = x - radius;
this.leftHandleY = y - radius;
int xDifference = oldLeftHandleX - this.leftHandleX;
int yDifference = oldLeftHandleY - this.leftHandleY;
this.rightHandleX -= xDifference;
this.rightHandleY -= yDifference;
// left blade
this.leftBladeStartX = leftHandleX + 2*radius;
this.leftBladeStartY = leftHandleY + radius;
this.leftBladeEndX -= xDifference;
this.leftBladeEndY -= yDifference;
// right blade
this.rightBladeStartX = rightHandleX;
this.rightBladeStartY = rightHandleY + radius;
this.rightBladeEndX -= xDifference;
this.rightBladeEndY -= yDifference;
}
public void moveRightHandle(int x, int y) {
int oldRightHandleX = this.rightHandleX;
int oldRightHandleY = this.rightHandleY;
this.rightHandleX = x - radius;
this.rightHandleY = y - radius;
int xDifference = oldRightHandleX - this.rightHandleX;
int yDifference = oldRightHandleY - this.rightHandleY;
this.leftHandleX += xDifference;
this.leftHandleY += yDifference;
// left blade
this.leftBladeStartX = leftHandleX + 2*radius;
this.leftBladeStartY = leftHandleY + radius;
this.leftBladeEndX -= xDifference;
this.leftBladeEndY -= yDifference;
// right blade
this.rightBladeStartX = rightHandleX;
this.rightBladeStartY = rightHandleY + radius;
this.rightBladeEndX += xDifference;
this.rightBladeEndY += yDifference;
}
public boolean isInsideLeftHandle(int x, int y) {
int centerX = leftHandleX + radius;
int centerY = leftHandleY + radius;
double distance = Math.sqrt(Math.pow(x-centerX, 2) + Math.pow(y-centerY, 2));
if (distance <= radius) {
return true;
}
return false;
}
public boolean isInsideRightHandle(int x, int y) {
int centerX = rightHandleX + radius;
int centerY = rightHandleY + radius;
double distance = Math.sqrt(Math.pow(x-centerX, 2) + Math.pow(y-centerY, 2));
if (distance <= radius) {
return true;
}
return false;
}
}