-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRay.pde
More file actions
79 lines (74 loc) · 1.82 KB
/
Ray.pde
File metadata and controls
79 lines (74 loc) · 1.82 KB
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
public class Ray extends Line{
Point Start = new Point();
PVector Versor = new PVector();
Ray() {
super();
Start = new Point();
Versor = new PVector();
Versor.normalize();
};
Ray(Point start, Point on) {
super(start, on);
Start = start;
Versor.y = on.y-start.y;
Versor.x = on.x-start.x;
Versor.normalize();
};
Ray(Point start, PVector V) {
super(start, start.Translate(V));
Start = start;
Versor = V;
Versor.normalize();
};
Ray(Ray R) {
super(R.Start, R.Start.Translate(R.Versor));
Start = R.Start.clone();
Versor = R.Versor.copy();
};
void Set(Point start, Point on) {
super.Set(start, on);
Start = start;
Versor.y = on.y-start.y;
Versor.x = on.x-start.x;
Versor.normalize();
};
void Set(Point start, PVector V) {
super.Set(start, start.Translate(V));
Start = start;
Versor = V;
Versor.normalize();
};
void Set(Ray R) {
super.Set(R.Start, R.Start.Translate(R.Versor));
Start = R.Start;
Versor = R.Versor;
};
public boolean CheckIfInFront(Point P) {
return cos(PVector.angleBetween(Versor, new PVector(P.x-Start.x, P.y-Start.y))) > 0;
};
public boolean CheckIfInFrontAndInInterval(Point P, float Interval) {
if(CheckIfInFront(P)) {
if(super.CalculateDistance(P) <= Interval) {
//strokeWeight(sightInterval);
//Draw(#FF00FF);
//super.Draw(#F0F0F0);
//strokeWeight(1);
return true;
}
else {
return false;
}
}
else {
return false;
}
};
public void Draw(color c) {
float maxLength = sqrt(sq(size[0]) + sq(size[1]));
Point Coord = Start.Translate(Versor.mult(maxLength));
stroke(c);
line(Start.x, Start.y, Coord.x, Coord.y);
//super.Draw(#F0F0F0);
noStroke();
};
}