-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotation_3.java
93 lines (76 loc) · 2.02 KB
/
Rotation_3.java
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
import Jcg.geometry.*;
import Jama.Matrix;
/**
* Define a 3D Rotation (using Euler angles)
*
* @author Luca Castelli Aleardi (INF555, 2014)
*/
public class Rotation_3 {
Matrix m;
/**
* The identity transformation
*/
public Rotation_3(Matrix m) {
this.m=m;
}
/**
* The identity rotation
*/
public Rotation_3() {
double[][] array = {{1.,0.,0.},
{0.,1.,0.},
{0.,0.,1.}};
this.m=new Matrix(array);
}
/**
* Return a rotation of an angle theta, around X axis
*/
public static Rotation_3 rotationAxisX(double theta) {
double[][] array = {
{1.,0.,0.},
{0.,Math.cos(theta),-Math.sin(theta)},
{0.,Math.sin(theta),Math.cos(theta)}};
return new Rotation_3(new Matrix(array));
}
/**
* Return a rotation of an angle theta, around Y axis
*/
public static Rotation_3 rotationAxisY(double theta) {
double[][] array = {
{Math.cos(theta),0.,Math.sin(theta)},
{0.,1., 0},
{-Math.sin(theta), 0., Math.cos(theta)}};
return new Rotation_3(new Matrix(array));
}
/**
* Return a rotation of an angle theta, around Z axis
*/
public static Rotation_3 rotationAxisZ(double theta) {
double[][] array = {
{Math.cos(theta),-Math.sin(theta), 0.},
{Math.sin(theta),Math.cos(theta), 0.},
{0.,0.,1.}};
return new Rotation_3(new Matrix(array));
}
/**
* Rotate point p
*/
public Point_3 transform(Point_3 p) {
double x=p.getCartesian(0).doubleValue();
double y=p.getCartesian(1).doubleValue();
double z=p.getCartesian(2).doubleValue();
double[][] array = {{x}, {y}, {z}};
Matrix v=new Matrix(array); // the vector
Matrix result=this.m.times(v);
double[] coord={result.get(0, 0), result.get(1, 0), result.get(2, 0)};
return new Point_3(coord[0], coord[1], coord[2]);
}
/**
* Compose two rotations
*/
public Rotation_3 compose(Rotation_3 t) {
Matrix M=t.m;
Matrix composition=this.m.times(M);
return new Rotation_3(composition);
}
}