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 floating-point numbers, as if they were coding in Fortran, sacrifice the units integrity, error checking, maintainability, and simplicity of objects.)
UsageGet the source code
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.
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(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
double theta.toRadians() double theta.toDegrees(); short theta.degrees(); short theta.minutes(); short theta.seconds(); // (rounded)
These pseudo-operators follow the design pattern for additive
classes and are named in accord with IDI's Java operator
naming conventions. In the examples
are Angle objects and
is a pure number, usually double.
|corresponding C++ expression||Java function syntax||result type if new object|
Note that because of normalization, the ordering relations are not transitive. Also, because of internal floating-point representation, testing for equality is unreliable.
a.tostring()yields the default external representation in integer degrees, minutes, and seconds,
|These methods return double||These inverse class functions return a new Angle object|
Note that an Angle class is an essential companion to a
class if users are to be given the choice of constructor
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