-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeriodicShape.pde
62 lines (56 loc) · 1.47 KB
/
PeriodicShape.pde
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
class PeriodicShape
{
private PVector center;
private PVector previous;
private Collection<Curve> curves;
private Collection<PVector> intersections;
private float angle;
private float tangent;
private final float DELTA_ANGLE = QUARTER_PI/30.0f;
private final float DELTA_TANGENT = tan(DELTA_ANGLE);
public PeriodicShape(PVector c)
{
center = c;
curves = new HashSet<Curve>();
previous = null;
intersections = new HashSet<PVector>();
angle = 0.0f;
tangent = 0.0f;
}
public void setLoc(float x, float y)
{
previous = new PVector(x, y);
}
public void lineTo(float x, float y)
{
PVector next = new PVector(x, y);
Segment seg = createSegment(center, previous, next);
curves.add(seg);
previous = next;
}
public Collection<PVector> update()
{
intersections.clear();
angle = (angle + DELTA_ANGLE) % TWO_PI;
tangent = (tangent + DELTA_TANGENT) / (1 - (tangent * DELTA_TANGENT));
for(Curve c : curves)
{
intersections.addAll(c.getPoints(angle, tangent));
c.draw();
}
for(PVector v : intersections)
{
line(center.x, center.y, v.x, v.y);
ellipse(v.x, v.y, 3, 3);
}
return intersections;
}
private Segment createSegment(PVector center, PVector point1, PVector point2)
{
if(abs(point1.x - point2.x) <= EPSILON)
{
return new VerticalSegment(center, point1, point2);
}
return new NonVerticalSegment(center, point1, point2);
}
}