Computer Graphics: Geometric Objects and Transformations
Computer Graphics: Geometric Objects and Transformations
2
Geometric objects in Java 2D
Quadratic curve: Two endpoints and a control point are
needed to define a quadratic curve.
QuadCurve2D.Float qc =
new QuadCurve2D.Float(x1,y1,ctrlx,ctrly,x2,y2);
Geometric objects in Java 2D
cubic curve: Two endpoints and two control points are needed
to define a cubic curve.
CubicCurve2D.Double cc =
new CubicCurve2D.Double(x1,y1,ctrlx1,ctrly1,ctrlx2,ctrly2,x2,y2);
GeneralPath class
General path: A GeneralPath is sequences of lines, quadratic
and cubic curves.
GeneralPath gp = new GeneralPath();
gp.moveTo(50,50);
gp.lineTo(50,200);
gp.quadTo(150,500,250,200);
gp.curveTo(350,-100,150,150,100,100);
gp.lineTo(50,50);
g2d.draw(gp);
GeneralPath class
A GeneralPath must always start with the method moveTo,
defining the starting point of the general path.
lineTo appends a line, starting from the (previous) last point
of the GeneralPath to the specified endpoint.
quadTo and curveTo append a quadratic and cubic curve,
respectively, starting from the (previous) last point of the
GeneralPath connecting it to the specified endpoint using the
given control points.
Axes-Parallel Rectangles
By the class Rectangle2D.Double, extending the abstract
class Rectangle2D, an axes-parallel rectangle can be defined
in the following way:
Rectangle2D.Double r2d =
new Rectangle2D.Double(x,y,width,height);
Ellipse
The ellipse can be drawn using
Ellipse2D.Double elli =
new Ellipse2D.Double(x,y, width,height);
Circle
Circle can be also drawn using given radius value and center
(x,y) coordinates.
Area objects
Geometric transformations
In addition to geometric objects, geometric transformations
play a crucial role in computer graphics.
Geometric transformations can be used to position objects,
i.e., to shift them to another position or to rotate them, to change the
shape of objects, for instance to stretch or shrink them in one
direction, or to move objects or change the shape of objects step by
step in animated scenes.
The most important geometric transformations are
Scaling, Rotation, Shearing and translation.
Geometric Transformations
Scaling
Rotation
Shearing
Translation.
Note: If the scaling factor S is less than 1, then we reduce
the size of the object. If the scaling factor S is greater than
Scaling 1, then we increase size of the object.