summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/transforms/geom/TDHRotation.java
blob: 8870b531ce0490e073a846f2baa773f1ea6fe726 (plain)
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
package bezier.transforms.geom;

import bezier.geom.TDHPoint;

public class TDHRotation implements TDHTransform {
	public final double theta;

	public TDHRotation(double theta) {
		this.theta = theta;
	}

	@Override
	public TDHPoint transform(TDHPoint punkt) {
		double x = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta));
		double y = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta));

		return new TDHPoint(x, y, punkt.z);
	}

	public double[][] matrix() {
		return new double[][] { new double[] { Math.cos(theta), Math.sin(theta), 0 },
				new double[] { -Math.sin(theta), Math.cos(theta), 0 }, new double[] { 0, 0, 1 } };
	}

	public TDHTransform invert() {
		return new TDHRotation(-theta);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(theta);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TDHRotation other = (TDHRotation) obj;
		if (Double.doubleToLongBits(theta) != Double.doubleToLongBits(other.theta))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "TDHRotation [theta=" + theta + "]";
	}
}