Create some Java classes which represent mathematical objects.
Java is an object oriented programming language, meaning that the programmer creates "objects," which can "do" various things
using method calls. The things an object might do when a method is called include changing the objects internal state, creating a new object,
modifying an object that is passed as a parameter to the method.
Object oriented languages are well suited to represent mathematics, because we tend to thing of basic mathematical concepts as objects.
Such a view goes back to Plato, who thought of mathematical objects as existing
in a "world of ideal Forms."
In any case, the most basic mathematical concepts can naturally be converted into objects in Java:
- Numbers can be treated as Java objects
as our Complex number class demonstrates.
- The LineSegment
class gives a basic example of
a geometric object implemented in Java.
- Mathematical functions can often be converted into Java objects as the Similarity
class demonstrates.
- Now you can begin to imagine how more complicated objects could be constructed. A mathematical group after all consists of
an identity element, a notion of group multiplication, and a inverse map. These things can all be understood in Java.
A good strategy for programming in Java is to take existing source code and modify it to suit your needs. Some more Java classes
which implement mathematical ideas are available here:
- Package finitecyclicgroup
- Package number
- File BigComplex.java: High precision representation of complex numbers with floating point real and imaginary parts.
- File Complex.java: An alternate complex number class.
- File RationalDemo.java: Demonstrates the use of the Rational and RationalField classes.
- File RationalField.java: Class for performing algebraic operations on Rational numbers.
- File Rational.java: Represents a rational number (based on the BigInteger class).
- Package projectiveplane
You can download all these files from this page.
As you create your mathematical objects, you should continually test what you are doing by writing simple executable programs
that print the results of operations you have created.
Displaying Mathematical Graphics
When creating a program to display mathematical graphics, you should follow the same ideas as above. You should modify existing source code
to do what you want.
I've created three "templates" for graphical programs below.
- Package justdrawing
- Package drawsomething
- File Complex.java: A complex number class.
- File DrawSomething.java: Modifies the DrawingDemo class to draw a logarithmic spiral using the Complex number class.
- Package simplermouseinteraction
- Package mouseinteraction
- Package coordinatechanges
- File DemoFrame.java: This class implements a window which contains a DemoPanel. The window has a menu bar and a status bar. Click here to run it.
- File DemoPanel.java: This is a simple panel (part of a window) which dispays some mathematical graphics. It converts objects from math to screen coordinates before dispaying them using the TransformManager class.
- File TransformChangedListener.java: This is an interface that allows a TransformManager to notify a panel when the coordinate transformation has changed.
- File TransformManager.java: Manages a coordinate change from math-coordinates to screen coordinates. The class guarantees that a certain rectangle will be displayed.
You can download all these files from this page.