DUE DATES:
This program requires you to design, implement and test a templated class called Polyline. The Polyline class represents a connected sequence of three-dimensional line segments. You are to write a program demonstrating your classes that generates a set of Polylines approximating several mathematically defined shapes including spiral curves, sine waves, and Kock snowflakes. The assignment will give you experience in developing a clear specification from a problem statement, experience in the use of linked lists, and additional experience in software coding and testing.
p = ((1.0,1.0,0.0), (-1.0,1.0,0.0), (-1.0,-1.0,0.0),
(1.0,-1.0,0.0), (1.0,1.0,0.0)defines four line segments that form a square in the z=0 plane centered on the origin as pictured below.
In addition to its shape, a Polyline should have a color attribute expressed by three values giving red, green, and blue components of the color. You should use the Point3D class from the first project to represent the points in a line segment.
A Polyline must be represented as a linked list of points.
You may choose to use either a singly or doubly linked list.
You should base the Node class and linked list toolkit on the versions defined
in the text. A templated version of this code is available in the class account
in the directory /group/class/c030/programs/chapter6.
The node structure for a singly linked list is pictured
below.
The Polyline class should include the following functions and operations:
p1 = p2;
p3 = p1 + p2;
p.rotateX(angle);
p.rotateY(angle);
p.rotateZ(angle);
p.shift(shiftx, shifty, shiftz);where shiftx, shiftx, and shiftx are doubles giving the amount to shift in the x, y, and z directions.
p.colorset(red, green, blue);
rvalue = p.colorgetRed();
gvalue = p.colorgetGreen();
bvalue = p.colorgetBlue();where red, green, and blue are the components of the color. The values of red, green, and blue must be in the range 0.0-1.0.
# Demonstrates a simple indexed lineset
Shape {
geometry IndexedLineSet {
coord Coordinate {
point [
# A sequence of five 3 dimensional points
0.0 0.0 0.0,
1.0 0.0, 0.0,
1.0 1.0, 0.0,
1.0 1.0, 1.0,
2.0 1.0, 1.0,
]
}
coordIndex [
# Indices of point to connects
0, 1, 2, 3, 4, -1,
]
color Color {
color [
# Red, Green, Blue values to color lines
1.0 .5 0.0
]
} # end color
# Flag indicating to color the whole line
colorPerVertex FALSE
} # End geometry IndexedLineSet
} # End Shape
The format includes definitions for the coordinates of the end points of
the line segments, the indices of the points to be connected, and the color
of the line.
The three color values
are the red, green, and blue components.
You should print all of the points
in the polyline here. The LineSet defintion indicates that the preceeding
points should be interpreted as a line set.
For an example of an output file containing two polylines see the file
lines.wrl in the class programs directory (/group/class/22c030/programs).
To package the shape in VRML format you must include the following line at
the beginning of your file:
#VRML V2.0 utf8
For an example of an output file containing two polylines see the file
LineSet.wrl in the class programs directory (/group/class/22c030/programs).
%vrml LineSet.wrl