Class Curveline
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Canvas
|
+----Curveline
- class Curveline
- extends Canvas
- implements MouseListener, MouseMotionListener
The Curveline class is the canvas upon which the curve functions are
drawn. This class contains numerous functions, including a Bezier
algorithm and a B-Spline algorithm for parametric analysis of a
2D CAD curve. The same polygon control frame is used throughout.
The user can modify the frame with a mouse grab and drag technique.
The user can see immediately the affect of a control point movement on
the shape of the curved line. Additionally, the user has the option to
reset the polygon control frame to it's original values.
Note: The mathmatical functions used in this program came from the
text "Curves and Surfaces for CAGD" by Gerald Farin, c.1993, Academic Press,
San Diego, CA. See the blossom technique for developing a Bezier Curve
by subdivision. See Farin, pg. 51-53 for routine, and fig 3.1 on pg. 30
for an intuitive description of what is actually happening...
Note: This first exercise in Java for the writer was not written with
strict reuse in mind. To enable speed in development, many of the routines,
which should be written as independent classes for reuse, are instead
highly integrated within other classes. (How do you pass an array to
another class within Java, anyway?)
Additional info: This class was originally designed as private, but
made public in the interest of the JavaDoc exercise.
-
CursorGrabSize
-
-
CurveColorDefault
-
-
CurveColorTemp
-
-
Debug
-
-
DragIndex
-
-
FrameColorDefault
-
-
FrameColorTemp
-
-
FrameControlPt
-
-
Knot
-
-
LineType
-
-
N
-
-
NumberOfControlPoints
-
-
NumberOfDots
-
-
Weight
-
-
WhichKnot
-
-
WhichWeight
-
-
Xtemp
-
-
Ytemp
-
-
Curveline(String)
- This sets up different variables required by the canvas sketch system
-
bezierCalculate(Graphics)
- This routine plots out a bezier curve, with multiple calls to hornbez()
-
BSplineCalculate(Graphics)
- This routine does a uniform B-Spline evaluation.
-
deboor(int, int, float, int)
- This routine taken from Gerald Farin, Curves and Surfaces for CAGD;
This routine uses de Boor algorithm to compute one
coordinate on B-spline curve for param.
-
drawBigPoint(Graphics, int, int)
- This routine draws each curve 'dot' (highly visible).
-
drawBigPointDottedLine(Graphics, int, int, int, int, int)
- This routine draws a dotted line between two points, using a large dot.
-
drawCursor(Graphics, int, int)
- Draw a large cursor (an X plus a small circle)
-
drawDottedLine(Graphics, int, int, int, int, int)
- This routine draws a dotted line between two points, using a small dot.
-
drawEllipseSegment(Graphics, int, int, int, int, int)
- This routine draws a simple elliptical 1/4 segment.
-
drawPoint(Graphics, int, int)
- This routine draws a small dot (one pixel!)
-
hornbez(int, int, float)
- This routine uses Horner's scheme to compute one coordinate
value of a Bezier curve.
-
initializeFrame()
- Initialize and reset the original values of the control frame and
of the curve line knot sequence.
-
mouseClicked(MouseEvent)
-
-
mouseDragged(MouseEvent)
- This routine drags the cursor across the workspace.
-
mouseEntered(MouseEvent)
-
-
mouseExited(MouseEvent)
-
-
mouseMoved(MouseEvent)
-
-
mousePressed(MouseEvent)
- This routine allows the user to 'grab' a polygon control vertice and
drag it across the screen.
-
mouseReleased(MouseEvent)
-
-
paint(Graphics)
- Paint and rePaint the screen with the control frame and with the 2D
curves! As there are different curves shown with this class, there
are numerous parametric tests to member variable "LineType".
FrameControlPt
int FrameControlPt[][]
N
int N
Knot
float Knot[][]
WhichKnot
int WhichKnot
Weight
float Weight[][]
WhichWeight
int WhichWeight
Xtemp
int Xtemp
Ytemp
int Ytemp
NumberOfControlPoints
int NumberOfControlPoints
DragIndex
int DragIndex
NumberOfDots
int NumberOfDots
CursorGrabSize
int CursorGrabSize
Debug
boolean Debug
FrameColorDefault
Color FrameColorDefault
FrameColorTemp
Color FrameColorTemp
CurveColorDefault
Color CurveColorDefault
CurveColorTemp
Color CurveColorTemp
LineType
String LineType
Curveline
public Curveline(String lt)
- This sets up different variables required by the canvas sketch system
initializeFrame
public void initializeFrame()
- Initialize and reset the original values of the control frame and
of the curve line knot sequence.
paint
public void paint(Graphics g)
- Paint and rePaint the screen with the control frame and with the 2D
curves! As there are different curves shown with this class, there
are numerous parametric tests to member variable "LineType".
- Overrides:
- paint in class Canvas
BSplineCalculate
public void BSplineCalculate(Graphics g)
- This routine does a uniform B-Spline evaluation. It looks closely at the
order and control information and thru nested for loops, determines both
X and Y coordinates for each point on the 2D curve of choice. This routine
makes numerous calls to the routine deboor. The 2D curved line of interest is plotted
directly from this routine.
deboor
public float deboor(int degree,
int xORy,
float u,
int i)
- This routine taken from Gerald Farin, Curves and Surfaces for CAGD;
This routine uses de Boor algorithm to compute one
coordinate on B-spline curve for param. value u in interval i.
input: degree: polynomial degree of each piece of curve
coeff: B-spline control points
knot: knot sequence
u: evaluation abscissa
i: u's interval: u[i]<= u < u[i+1]
output: coordinate value.
for use of Farin's algorithm DeBoor algorithm, see bspl_to_points.c file...
See also sketch in Farin, pg. 166
bezierCalculate
public void bezierCalculate(Graphics g)
- This routine plots out a bezier curve, with multiple calls to hornbez()
hornbez
public float hornbez(int degree,
int xORy,
float t)
- This routine uses Horner's scheme to compute one coordinate
value of a Bezier curve. Has to be called
for each coordinate (x,y, and/or z) of a control polygon.
See Farin, pg 59,60. Note: This technique is also called
"nested multiplication".
Input: degree: degree of curve.
coeff: array with coefficients of curve.
t: parameter value.
Output: coordinate value.
drawEllipseSegment
public void drawEllipseSegment(Graphics tempGraphics,
int x1,
int y1,
int x2,
int y2,
int numOfDots)
- This routine draws a simple elliptical 1/4 segment. It is a little different
in that the control polygon defines the 1/4 segment endpoints instead of
Ellipse center point and outer frame corner. This routine can be called
four times to create a complete ellipse or circle.
mousePressed
public void mousePressed(MouseEvent me)
- This routine allows the user to 'grab' a polygon control vertice and
drag it across the screen. The grab looks at each control point in an array
and asks the question, 'Is this point within a certain distance from
the initial mouse button press cursor? The window is fairly small.
The loop routine (and breakout) allows for controlled stacking of control points,
so the points can be stacked upon each other one at a time, and then
removed again, one at a time.
mouseDragged
public void mouseDragged(MouseEvent me)
- This routine drags the cursor across the workspace. It repaints the
window at each movement. This routine is magic, enabling the user
to see what is happening within the curve algorithm. This routine
is absolutely essential to the functioning of the program. Although
there is some display blinking visible, this makes the examples come alive!
mouseMoved
public void mouseMoved(MouseEvent me)
mouseReleased
public void mouseReleased(MouseEvent me)
mouseEntered
public void mouseEntered(MouseEvent me)
mouseExited
public void mouseExited(MouseEvent me)
mouseClicked
public void mouseClicked(MouseEvent me)
drawDottedLine
public void drawDottedLine(Graphics tempGraphics,
int x1,
int y1,
int x2,
int y2,
int numOfDots)
- This routine draws a dotted line between two points, using a small dot.
All control polygon lines are drawn in this technique.
drawBigPointDottedLine
public void drawBigPointDottedLine(Graphics tempGraphics,
int x1,
int y1,
int x2,
int y2,
int numOfDots)
- This routine draws a dotted line between two points, using a large dot.
drawPoint
public void drawPoint(Graphics tempGraphics,
int x,
int y)
- This routine draws a small dot (one pixel!)
drawBigPoint
public void drawBigPoint(Graphics tempGraphics,
int x,
int y)
- This routine draws each curve 'dot' (highly visible).
drawCursor
public void drawCursor(Graphics tempGraphics,
int x,
int y)
- Draw a large cursor (an X plus a small circle)