A Protractor with an arrow that can be used to measure angles. @author W. Christian @version 1.0
| 24 | * @version 1.0 |
| 25 | */ |
| 26 | public class Protractor extends InteractiveCircle implements Drawable { |
| 27 | static final double PI2 = Math.PI*2; |
| 28 | static final String thetaStr = "$\\theta$="; //$NON-NLS-1$ |
| 29 | int protractorRadius, protractorRadius2, arrowLengthPix; |
| 30 | protected Tip tip = new Tip(); |
| 31 | protected double arrowTheta = 0, orientation = 0; |
| 32 | protected DecimalFormat f = org.opensourcephysics.numerics.Util.newDecimalFormat("000"); //$NON-NLS-1$ |
| 33 | protected boolean showTheta = false; |
| 34 | protected InteractiveLabel tauBox = new InteractiveLabel(thetaStr+f.format(getTheta())); |
| 35 | |
| 36 | /** |
| 37 | * Constructs a protractor with the given pixel size. |
| 38 | * |
| 39 | * @param protractorRadius int |
| 40 | */ |
| 41 | public Protractor(int protractorRadius) { |
| 42 | this.protractorRadius = protractorRadius; |
| 43 | protractorRadius2 = protractorRadius*2; |
| 44 | arrowLengthPix = protractorRadius; |
| 45 | tip.color = Color.BLUE; |
| 46 | tauBox.setOffsetX(-20); |
| 47 | tauBox.setOffsetY(5); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Constructs a protractor with a default radius of 40 pixels. |
| 52 | */ |
| 53 | public Protractor() { |
| 54 | this(40); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Sets the angle of the arrow on the protractor. |
| 59 | * @param theta double |
| 60 | */ |
| 61 | public void setTheta(double angle) { |
| 62 | this.arrowTheta = angle+orientation; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Gets the angle of the arrow on the protractor. |
| 67 | * @return double |
| 68 | */ |
| 69 | public double getTheta() { |
| 70 | // return PBC.separation(arrowTheta-orientation,Math.PI*2); |
| 71 | // inline the method for efficiency and to decouple from the numerics package |
| 72 | double dr = arrowTheta-orientation; |
| 73 | return dr-PI2*Math.floor(dr/PI2+0.5); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sets the orientation of the protractor. |
| 78 | * @param angle double |
| 79 | */ |
| 80 | public void setOrientation(double angle) { |
| 81 | this.orientation = angle; |
| 82 | } |
| 83 |
nothing calls this directly
no test coverage detected