- english
- /
- japanese
methods
- addVertex()
- addVertexes()
- addVertices()
- arc()
- arcNegative()
- bezierTo()
- clear()
- close()
- curveTo()
- draw()
- fromRectangle()
- getArea()
- getBoundingBox()
- getCentroid2D()
- getClosestPoint()
- getPerimeter()
- getResampledByCount()
- getResampledBySpacing()
- getSmoothed()
- getVertices()
- hasChanged()
- inside()
- isClosed()
- lineTo()
- operator[]()
- quadBezierTo()
- resize()
- setClosed()
- simplify()
- size()
ofPolyLine allows you to combine multiple points into a single vector data object that can be drawn to the screen, manipulated point by point, and combined with other ofPolyline instances. It is less complex than the ofPath and generally represents a single line or vector shape rather than multiple lines or shapes.
You can add points to an ofPolyline by adding vertices:
float i = 0;
while (i < TWO_PI) { // make a heart
float r = (2-2*sin(i) + sin(i)*sqrt(abs(cos(i))) / (sin(i)+1.4)) * -80;
float x = ofGetWidth()/2 + cos(i) * r;
float y = ofGetHeight()/2 + sin(i) * r;
line.addVertex(ofVec2f(x,y));
i+=0.005*HALF_PI*0.5;
}
line.close(); // close the shape
or you can draw lines or curves:
float angle = 0;
while (angle < TWO_PI ) {
b.curveTo(100*cos(angle), 0, 100*sin(angle));
b.curveTo(300*cos(angle), 300, 300*sin(angle));
angle += TWO_PI / 30;
}
ofPolyline also includes methods to get the cloeset point, determien whether a point is inside shape, and resample shapes. Along with the ofPath class, it's the best way to draw and manipulate 2D and 3D vector graphics that you'll need to update and manipulate frequently. If you use the line or curveTo or bezierTo functions, you move the drawing point, so that drawing a line to 100,100 means a line from 0,0 to 100, 100. The next line would be a line from 100,100 to whereever you go next. Storing this position means that you can easily create continuous drawings without difficulty.
addVertex(...)
void ofPolyline::addVertex(const ofPoint &p)
Adds a point using an ofPoint at the end of the ofPolyline.
addVertex(...)
void ofPolyline::addVertex(float x, float y, float z=0)
Adds a point using floats instead of an ofPoint at the end of the ofPolyline.
addVertexes(...)
void ofPolyline::addVertexes(const vector< ofPoint > &verts)
Adds multiple points at the end of the ofPolyline using a vector of ofPoint objects, which can be declared like so:
vector<ofPoint> verts;
// make a pentagon
float size = 80.f;
float X1 = 0.125*sqrt(10 + 2*sqrt(5)) * size;
float X2 = 0.125*sqrt(10 - 2*sqrt(5)) * size;
float Y1 = 0.125*(sqrt(5) - 1) * size;
float Y2 = 0.125*(sqrt(5) + 1) * size;
verts.push_back(ofPoint(0, -0.5 * size));
verts.push_back(ofPoint(-X1, -Y1));
verts.push_back(ofPoint(-X2, Y2));
verts.push_back(ofPoint(X2, Y2));
verts.push_back(ofPoint(X1, -Y1));
ofPolyline p;
p.addVertexes(verts);
addVertexes(...)
void ofPolyline::addVertexes(const ofPoint *verts, int numverts)
Adds multiple points at the end of the ofPolyline using a pointer to an array of ofPoint objects.
ofPoint* verts = new ofPoint[5];
// make a pentagon
float size = 80.f;
float X1 = 0.125*sqrt(10 + 2*sqrt(5)) * size;
float X2 = 0.125*sqrt(10 - 2*sqrt(5)) * size;
float Y1 = 0.125*(sqrt(5) - 1) * size;
float Y2 = 0.125*(sqrt(5) + 1) * size;
verts[0] = ofPoint(0, -0.5 * size);
verts[1] = ofPoint(-X1, -Y1);
verts[2] = ofPoint(-X2, Y2);
verts[3] = ofPoint(X2, Y2);
verts[4] = ofPoint(X1, -Y1);
ofPolyline p;
p.addVertexes(verts, 5);
arc(...)
void ofPolyline::arc(const ofPoint ¢er, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
Draw an arc around the ofPoint p with the width of radiusX and the height of radiusY. The angleBegin and angleEnd indicate how far around you want the arc to extend. For instance, to draw a circle:
ofPoint p(0, 0);
polyline.arc(p,100,100,0,360,40); // circle with a diameter of 100
ofPoint p(100, 0);
polyline.arc(p,100,100,0,180,40); // semi-circle with a diameter of 100
arc(...)
void ofPolyline::arc(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
Draw an arc around the point x,y with the width of radiusX and the height of radiusY. The angleBegin and angleEnd indicate how far around you want the arc to extend. For instance, to draw a circle:
polyline.arc(0,0,100,100,0,360,40); // circle with a diameter of 100
polyline.arc(0,0,100,100,0,180,40); // semi-circle with a diameter of 100
arc(...)
void ofPolyline::arc(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
Draw an arc around the point x,y,z with the width of radiusX and the height of radiusY. The angleBegin and angleEnd indicate how far around you want the arc to extend. For instance, to draw a circle:
// at middle and -100 back
polyline.arc(ofGetWidth()/2,ofGetHeight()/2,100,100,100,0,360,40); // circle with a diameter of 100
// at middle and -100 back
polyline.arc(ofGetWidth()/2,ofGetHeight()/2,100,100,100,0,180,40); // semi-circle with a diameter of 100
arc(...)
void ofPolyline::arc(const ofPoint ¢er, float radiusX, float radiusY, float angleBegin, float angleEnd, bool clockwise, int curveResolution=20)
arcNegative(...)
void ofPolyline::arcNegative(const ofPoint ¢er, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
arcNegative(...)
void ofPolyline::arcNegative(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
arcNegative(...)
void ofPolyline::arcNegative(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int curveResolution=20)
bezierTo(...)
void ofPolyline::bezierTo(const ofPoint &cp1, const ofPoint &cp2, const ofPoint &to, int curveResolution=16)
Creates a cubic bezier line from the current drawing point with the 2 control points indicated by ofPoint cp1 and cp2, that ends at ofPoint to. For instance, the following:
line.addVertex(ofPoint(200, 400));
line.bezierTo(100, 100, 800, 100, 700, 400);
Creates this:
The control points are shown in yellow.
bezierTo(...)
void ofPolyline::bezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution=16)
Creates a cubic bezier line from the current drawing point with the 2 control points indicated by the coordinates cx1, cy1 and cx2, cy2, that ends at the coordinates x, y.
bezierTo(...)
void ofPolyline::bezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z, int curveResolution=16)
Creates a cubic bezier line in 3D space from the current drawing point with the 2 control points indicated by the coordinates cx1, cy1, cz1 and cx2, cy2, cz2, that ends at the coordinates x, y, z.
float cx = ofGetWidth()/2;
float cy = 200;
float step = TWO_PI / 60;
for (float i = 0.0; i < TWO_PI; i+=step) {
if(i == 0.0) {
line.addVertex(cx + (400*cos(i)), cy+400, 400 * sin(i));
} else {
line.bezierTo( cx - (200*cos(i)), cy-100, 400 * sin(i),
cx + (200*cos(i)), cy+600, 400 * sin(i),
cx + (400*cos(i)), cy+400, 400 * sin(i));
}
}
close()
void ofPolyline::close()
Closes the ofPolyline, meaning that all the vertices will be linked and can be "walked".
curveTo(...)
void ofPolyline::curveTo(const ofPoint &to, int curveResolution=16)
Draws a curve to an ofPoint object passed in:
float angle = 0;
while (angle < TWO_PI ) {
b.curveTo( ofPoint(100*cos(angle), 100*sin(angle)));
b.curveTo( ofPoint(300*cos(angle), 300*sin(angle)));
angle += TWO_PI / 30;
}
curveTo(...)
void ofPolyline::curveTo(float x, float y, float z=0, int curveResolution=16)
Draws a curve to the x,y,z points passed in with the optional resolution.
float angle = 0;
while (angle < TWO_PI ) {
polyline.curveTo(100*cos(angle), 0, 100*sin(angle));
polyline.curveTo(300*cos(angle), 300, 300*sin(angle));
angle += TWO_PI / 30;
}
getBoundingBox()
ofRectangle ofPolyline::getBoundingBox()
Returns the bounding box of the shape, taking into account all the points to determine the extents of the polyline.
getClosestPoint(...)
ofPoint ofPolyline::getClosestPoint(const ofPoint &target, unsigned int *nearestIndex=NULL)
This returns the point on the line closest to the target. You can also optionally pass a pointer to/address of an unsigned int to get the index of the closest vertex.
getPerimeter()
float ofPolyline::getPerimeter()
Returns the size of the perimeter of the polyline, good for determining length of the line, rather than just the bounding box shape.
getResampledByCount(...)
ofPolyline ofPolyline::getResampledByCount(int count)
This resamples the line based on the spacing passed in. The lower the count passed in, the more points will be eliminated. This doesn't add new points to the line though.
getResampledBySpacing(...)
ofPolyline ofPolyline::getResampledBySpacing(float spacing)
This resamples the line based on the spacing passed in. The larger the spacing, the more points will be eliminated.
line.draw();
ofTranslate(400, 0);
line.getResampledBySpacing(100).draw();

getSmoothed(...)
ofPolyline ofPolyline::getSmoothed(int smoothingSize, float smoothingShape=0)
This returns a smoothed version of the ofPolyline.
getVertices()
ofPoint ofPolyline::getVertices()
Returns the vector of vertices that the line contains, vector
hasChanged()
bool ofPolyline::hasChanged()
Returns whether the vertices within the line have changed.
inside(...)
bool ofPolyline::inside(float x, float y)
Tests whether the x,y coordinates are within a closed ofPolyline.
inside(...)
bool ofPolyline::inside(const ofPoint &p)
Tests whether the ofPoint is within a closed ofPolyline.
inside(...)
bool ofPolyline::inside(float x, float y, const ofPolyline &polyline)
Test whether the x,y point is within anothe polyline, passed in as ofPolyline&
inside(...)
bool ofPolyline::inside(const ofPoint &p, const ofPolyline &polyline)
Test whether the ofPoint is within anothe polyline, passed in as ofPolyline&
isClosed()
bool ofPolyline::isClosed()
Whether the shape is closed or not. Certain operations, like getSmoothed() can only be performed on closed shapes.
lineTo(...)
void ofPolyline::lineTo(const ofPoint &to)
Add a line from the last point added, or from 0,0 if no point is set, to the point indicated by the ofPoint passesd in.
lineTo(...)
void ofPolyline::lineTo(float x, float y, float z=0)
Add a line from the last point added, or from 0,0 if no point is set, to the point indicated by the floats x,y,z passesd in.
operator[](...)
The [] operator allows you to access the points of the ofPolyline just like you would in an array, so to make the points of a line follow the mouse movement, you could do:
line[0].set(mouseX, mouseY);
int i = 1;
while ( i<bounds.size()) {
float angle = atan2(line[i-1].y - line[i].y, line[i-1].x - line[i].x);
bounds[i].set(bounds[i-1].x - cos(angle) * 20, bounds[i-1].y - sin(angle) * 20);
i++;
}
quadBezierTo(...)
void ofPolyline::quadBezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z, int curveResolution=16)
Creates a quadratic bezier line in 3D space from the current drawing point with the beginning indicated by the coordinates cx1, cy1, cz1, the control point at cx2, cy2, cz2, and that ends at the coordinates x, y, z.

quadBezierTo(...)
void ofPolyline::quadBezierTo(const ofPoint &p1, const ofPoint &p2, const ofPoint &p3, int curveResolution=16)
Creates a quadratic bezier line in 2D space from the current drawing point with the beginning indicated by the point p1, the control point at p2, and that ends at the point p3.
quadBezierTo(...)
void ofPolyline::quadBezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution=16)
Creates a quadratic bezier line in 3D space from the current drawing point with the beginning indicated by the coordinates cx1, cy1, the control point at cx2, cy2, and that ends at the coordinates x, y.
resize(...)
void ofPolyline::resize(size_t size)
Resize the number of points in the ofPolyline to the value passed in.
setClosed(...)
void ofPolyline::setClosed(bool tf)
Closes the ofPolyline, meaning that all the vertices will be linked and can be "walked".
simplify(...)
void ofPolyline::simplify(float tolerance=0.3)
Simplifies the polyline, removing un-necessary vertices. The tolerance determines how dis-similar points need to be to stay in the line. Higher tolerance means more points removed, lower tolerance means less points removed.
Last updated
Thursday, 16 May 2013 14:01:02 UTC
-
cbf0910627a25e6153f2452833c5313fe6067059

