1
2 package hep.wired.heprep.projection;
3
4 import hep.wired.heprep.services.Projection;
5 import hep.wired.feature.Resetable;
6
7 /***
8 * Shows azimuthal region in detail while displaying the full 360 degrees.
9 * Formula: phi' = phi0 + PI + ((d*PI)*dPhi)/((d*PI)+PI-|dPhi|)
10 * where rho is constant, dPhi = phi - phi0 - PI
11 * and d is between 0 and INF.
12 *
13 * @author Mark Donszelmann
14 * @version $Id: ClockProjection.java 2136 2005-07-30 00:25:21Z duns $
15 */
16
17 public class ClockProjection extends VariableProjection implements Resetable {
18
19 private static final double PI = Math.PI;
20 private static final double PI2 = PI*2;
21 private double resetD, resetPhi0;
22 private double d, phi0;
23
24 public ClockProjection() {
25 this(0.1, 0.1, 0, 0);
26 }
27
28 private ClockProjection(double d, double resetD, double phi0, double resetPhi0) {
29 super("Clock");
30 addVariable("d", 0.0, Double.MAX_VALUE, d, "rad", "Clock aperture angle");
31 addVariable("phi0", -Double.MAX_VALUE, Double.MAX_VALUE, phi0, "rad", "Clock angle");
32 this.resetD = resetD;
33 this.resetPhi0 = resetPhi0;
34 }
35
36 public String getFormula() {
37 return "(u,v,w) = ";
38 }
39
40 public double[] transform(double[] xyz) {
41 double x = xyz[X];
42 double y = xyz[Y];
43 double z = xyz[Z];
44
45 double phi = Math.atan2(y, x);
46 double rho = Math.sqrt((x*x) + (y*y));
47
48 double dPhi = phi - phi0 - PI;
49
50 dPhi = (dPhi + PI + PI2) % PI2 - PI;
51
52 double dPI = PI/d;
53
54 double phiPrime = phi0 + PI + (dPI*dPhi) / (dPI+PI-Math.abs(dPhi));
55
56 xyz[U] = rho * Math.cos(phiPrime);
57 xyz[V] = rho * Math.sin(phiPrime);
58 xyz[W] = z;
59
60 return xyz;
61 }
62
63 public double[] deltaTransform(double[] xyz) {
64 return transform(xyz);
65 }
66
67 public double[] inverseTransform(double[] uvw) throws UnsupportedOperationException {
68 throw new UnsupportedOperationException("No inverse transform on "+getClass());
69 }
70
71 public double[] inverseDeltaTransform(double[] uvw) throws UnsupportedOperationException {
72 return inverseTransform(uvw);
73 }
74
75 public Projection copy() {
76 return new ClockProjection(d, resetD, phi0, resetPhi0);
77 }
78
79
80 public Object reset(Object newState) {
81 Object oldState = new double[] { d, phi0 };
82 if (newState == null) {
83 d = resetD;
84 phi0 = resetPhi0;
85 } else {
86 double[] array = (double[])newState;
87 d = array[0];
88 phi0 = array[1];
89 }
90 return oldState;
91 }
92
93 }