- Forward


Vector Graphics
A Simplified Approach with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Representation of Visual Content
Back SMYC Forward
  • Raster Representation:
    • Content is thought of as a grid/matrix (spatial discretization)
    • Each picture element (i.e., pixel) contains one color
    • Set of colors is determined by the palette (color quantization)
  • Vector Representation:
    • Content is thought of as a set of shapes (e.g., points, lines, polygons/rectangles/ovals)
    • Shapes are defined using intension, not extension
Rendering of Visual Content
Back SMYC Forward
  • Purpose:
    • Present visual content on an output device
  • Devices:
    • Discrete rendering (e.g., LCD panels have physical pixels)
    • Continuous rendering (e.g., pen plotters)
Some Observations
Back SMYC Forward
  • The representation can be (and usually is) independent of the renderer
  • We are concerned only with the representation
Simplified Vector Graphics
Back SMYC Forward
  • Concepts:
    • Paper - the material being drawn on
    • Pen - the instrument used to do the drawing
    • Ink - the material in the pen that changes the color of the paper
  • Operations:
    • setPaperColor(name:String)
    • setInkColor(name:String)
    • setPenWidth(pixels:int)
    • setLineType(name:String)
    • moveTo(p:Point)
    • drawTo(p:Point)
Simplified Vector Graphics (cont.)
Back SMYC Forward

Coordinates

Drafter-coordinates
A Vector Graphics Class
Back SMYC Forward

Drafter

Drafter-overview
Required of the Analytic Geometry Classes
Back SMYC Forward
  • The Point Class:
    • Must have a method getCoordinate(i:int):double
    • The indexes must be 0-based
  • Other Classes:
    • Should have a method that returns an iterator of Point objects
A ConcreteDrafter
Back SMYC Forward

A Floor Plan

javaexamples/navigation/FloorPlanExample.java
 
Drawing Features
Back SMYC Forward

LineSegment

javaexamples/navigation/FeatureDrafter1.java (Fragment: 1)
 
Drawing Features (cont.)
Back SMYC Forward

PiecewiseLinearCurve

javaexamples/navigation/FeatureDrafter1.java (Fragment: 2)
 
Drawing Features (cont.)
Back SMYC Forward

Polygon

javaexamples/navigation/FeatureDrafter1.java (Fragment: 3)
 
Drawing Features (cont.)
Back SMYC Forward
  • The code for PiecewiseLinearCurve and Polygon are identical.
  • The code for LineSegment can be modified to work the same way.
  • It would be nice to be able to draw a Point.
Drawing Features (cont.)
Back SMYC Forward

All Classes that Implement Feature

javaexamples/navigation/FeatureDrafter2.java (Fragment: 1)
 
What About Re-Sizing?
Back SMYC Forward
  • Scaling:
    • Multiplying each Point in the Feature by a scalar
  • Translation:
    • Adding to each Point in the Feature
What About Re-Sizing? (cont.)
Back SMYC Forward

Coordinates

world-to-screen
Scaling
Back SMYC Forward
  • Determine the Range in World Coordinates:
    • \(\rho = w^{\mbox{max}} - w^{\mbox{min}}\)
  • Determine the Scale for Each Coordinate:
    • \(\sigma_{1} = s_{1}^{\mbox{max}} / \rho_{1}\)
    • \(\sigma_{2} = s_{2}^{\mbox{max}} / \rho_{2}\)
  • Maintain the Aspect Ratio:
    • \(\alpha = \min(\sigma_{1}, \sigma_{2})\)
  • Scale Each Point:
    • \(\hat{p} = \alpha p\)
Scaling (cont.)
Back SMYC Forward
  • Methods in Point:
    • Add and subtract Point objects
  • Methods to Add to Point?
    • Component-by-component multiplication/division
    • Smallest/largest component in a Point
Translating the Scaled Points
Back SMYC Forward
  • Scale the Minimum in World Coordinates:
    • \(\hat{w}^{\mbox{min}} = \alpha w^{\mbox{min}}\)
  • Translate the Scaled Point:
    • \(q = \hat{p} - \hat{w}^{\mbox{min}}\)
Translating the Scaled Points (cont.)
Back SMYC Forward
  • Methods in Point:
    • Multiply a scalar and a Point object
    • Add and subtract Point objects
  • Methods to Add to Point?
    • None
The Rectangular Hull
Back SMYC Forward
  • Defined:
    • The smallest rectangle that contains a set of points
  • Software Design Considerations:
    • Can be represented as two Point objects, the component-by-component minimum and maximum
    • Should be able to "adjust itself" for a new Point object or another RectangularHull object
  • Static Methods to Add to Point?
    • The component-by-component min and max of two Point objects
The Rectangular Hull (cont.)
Back SMYC Forward
  • Methods to add to Feature:
    • getRectangularHull():RectangularHull
  • Software Design Considerations:
    • Could be in an abstract parent but a particular class (i.e., LineSegment, PiecewiseLinearCurve, etc...) may be able to do it more efficiently
The Rectangular Hull (cont.)
Back SMYC Forward

One Possible Implementation

javaexamples/navigation/RectangularHull.java
 
Drawing Re-sized Features
Back SMYC Forward
javaexamples/navigation/FeatureDrafter3.java (Fragment: 1)
 
There's Always More to Learn
Back -