Conrad Weisert, Information Disciplines, Inc., Chicago
Many scientific and engineering applications as well as some business applications need to manipulate angles. (Java programmers who represent angles as primitive floatingpoint numbers, as if they were coding in Fortran, sacrifice the units integrity, error checking, maintainability, and simplicity of objects.)
UsageGet the source codeAngle.java , compile it, and store the
.class file in your directory path.
For compatibility with the Java Math library and other software, the range of values is (pi,pi], i.e. not [0,2pi). Normalization is automatic with all operations including constructors. Constructors 
What about the C++ version?Java may be a poor choice of language for computation that involves angles, because of both inefficiency and unnatural syntax. You'll find IDI's more efficient and more natural C++ Angle class in Conrad Weisert's book Object Oriented Computation in C++ and Java or contact IDI.  Usage documentation reminderWe've explained why we avoid the JAVADOC style of usage documentation. 
Angle(double radians) Angle(int deg, int min, int sec) // (See Note 1) Angle(int deg, int min) // (See Note 1) Angle(Angle theta) // (copy constructor) Angle() // (default value = 0)
Note 1: For these mixed unit constructors, the signs of the individual integer components
are treated algebraically; normally they should all be the same, e.g. to specify 22.5
degrees code Angle(22,30)
.
double theta.toRadians() double theta.toDegrees(); short theta.degrees(); short theta.minutes(); short theta.seconds(); // (rounded)
These pseudooperators follow the design pattern for additive
classes and are named in accord with IDI's Java operator
naming conventions. In the examples a1
and a2
are Angle objects and x
is a pure number, usually double.
corresponding C++ expression  Java function syntax  result type if new object 
a1 = a2  a1.set(a2)   
a1 += a2  a1.addSet(a2)   
a1 = a2  a1.subSet(a2)   
a1 *= x  a1.mpySet(x)   
a1 /= x  a1.divSet(x)   
a1 + a2  a1.add(a2)  Angle 
a1  a2  a1.sub(a2)  Angle 
a1 * x  a1.mpy(x)  Angle 
a1 / x  a1.div(x)  Angle 
a1 / a2  a2.div(a2)  double 
a1 == a2  a1.equals(a2)  boolean 
a1 < a2  a1.lessThan(a2)  boolean 
a1 > a2  a1.greaterThan(a2)  boolean 
Note that because of normalization, the ordering relations are not transitive. Also, because of internal floatingpoint representation, testing for equality is unreliable.
a.tostring()
yields the default external representation in integer
degrees, minutes, and seconds,45°0'0"
,
134°59'59"
These methods return double  These inverse class functions return a new Angle object 
a.cos()
 arccos(double x)

a.sin()
 arcsin(double x)

a.tan()
 arctan(double y, double x)


 arctan(double x)

Note that an Angle class is an essential companion to a
Complex
number
class if users are to be given the choice of constructor
coordinates:
Complex(realPart, imagPart) Complex(rho, theta)By overloading the
Complex
constructors to recognize
the difference between a double
and an
Angle
in the second parameter
we avoid ambiguity while giving the users both alternatives.
Return to Freeware directory
Return to IDI home page
Last modified August 2, 2005