-
Notifications
You must be signed in to change notification settings - Fork 1
/
rotate.java
79 lines (65 loc) · 1.89 KB
/
rotate.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
import com.cycling74.max.*;
public class rotate extends MaxObject {
float[] seqReal, seqImg;
float angle;
rotate() {
new PolToCar();
new CarToPol();
declareInlets(new int[] { DataTypes.LIST, DataTypes.LIST, DataTypes.FLOAT });
declareOutlets(new int[] { DataTypes.LIST, DataTypes.LIST });
}
protected void inlet(float v) {
final int idx = getInlet();
switch (idx) {
case 2:
angle = v;
bang();
break;
}
}
protected void list(Atom[] a) {
final int idx = getInlet();
switch (idx) {
case 0:
seqReal = Atom.toFloat(a);
bang();
break;
case 1:
seqImg = Atom.toFloat(a);
break;
}
}
private class CarToPol {
CarToPol() {
}
float t, r;
CarToPol(float x, float y) {
t = (float) Math.atan2(y, x);
r = (float) Math.sqrt((x * x) + (y * y));
}
}
private class PolToCar {
PolToCar() {
}
float x, y;
PolToCar(float t, float r) {
x = (float) (r * Math.cos(t));
y = (float) (r * Math.sin(t));
}
}
protected void bang() {
if (seqReal != null && seqReal.length > 0 && seqImg != null && seqImg.length > 0) {
int len = seqReal.length;
float[] outSeqReal = new float[len];
float[] outSeqImg = new float[len];
for (int i = 0; i < len; i++) {
CarToPol pol = new CarToPol(seqReal[i], seqImg[i]);
PolToCar car = new PolToCar(pol.t - angle, pol.r);
outSeqReal[i] = car.x;
outSeqImg[i] = car.y;
}
outlet(1, outSeqImg);
outlet(0, outSeqReal);
}
}
}