-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine.pde
53 lines (41 loc) · 1.85 KB
/
Line.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
class Line {
PVector v;
Line(float x, float y, float z) {
this.v = new PVector(x,y,z);
}
Line(PVector _v) {
this.v = _v.copy();
}
void rotateAtAround(PVector axis) {
PVector buffer = new PVector(0,0,0);
axis.normalize();
buffer.x = this.v.x*( 0.5 + pow(axis.x,2) * ( 0.5 ) )
+ this.v.y*( axis.x*axis.y*( 0.5 ) - axis.z*sqrt(3)/2 )
+ this.v.z*( axis.x*axis.z*( 0.5 ) + axis.y*sqrt(3)/2 );
buffer.y = this.v.x*( axis.y*axis.x*( 0.5 ) + axis.z*sqrt(3)/2 )
+ this.v.y*( 0.5 + pow(axis.y,2) * ( 0.5 ) )
+ this.v.z*( axis.y*axis.z*( 0.5 ) - axis.x*sqrt(3)/2 );
buffer.z = this.v.x*( axis.z*axis.x*( 0.5 ) - axis.y*sqrt(3)/2 )
+ this.v.y*( axis.z*axis.y*( 0.5 ) - axis.x*sqrt(3)/2 )
+ this.v.z*( 0.5 + pow(axis.z,2) * ( 0.5 ) );
this.v = buffer;
}
void rotateAtAround(float angle, PVector axis) {
PVector buffer = new PVector(0,0,0);
axis.normalize();
//println(cos(angle));
buffer.x = this.v.x*( cos(angle) + pow(axis.x,2) * ( 1-cos(angle) ) )
+ this.v.y*( axis.x*axis.y*( 1-cos(angle) ) - axis.z*sin(angle) )
+ this.v.z*( axis.x*axis.z*( 1-cos(angle) ) + axis.y*sin(angle) );
buffer.y = this.v.x*( axis.y*axis.x*( 1-cos(angle) ) + axis.z*sin(angle) )
+ this.v.y*( cos(angle) + pow(axis.y,2) * ( 1-cos(angle) ) )
+ this.v.z*( axis.y*axis.z*( 1-cos(angle) ) - axis.x*sin(angle) );
buffer.z = this.v.x*( axis.z*axis.x*( 1-cos(angle) ) - axis.y*sin(angle) )
+ this.v.y*( axis.z*axis.y*( 1-cos(angle) ) - axis.x*sin(angle) )
+ this.v.z*( cos(angle) + pow(axis.z,2) * ( 1-cos(angle) ) );
this.v = buffer;
}
void display() {
line(0,0,0,v.x,v.y,v.z);
}
}