reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofPolyline.h File Reference
#include "ofConstants.h"
#include "glm/fwd.hpp"
#include <deque>
#include "ofPolyline.inl"

Go to the source code of this file.

Classes

class  ofPolyline_< T >
 

Typedefs

using ofPolyline = ofPolyline_< ofDefaultVertexType >
 

Functions

template<class T >
bool ofInsidePoly (float x, float y, const std::vector< T > &polygon)
 Determine if an (x,y) coordinate is within the polygon defined by a vector of glm::vec3s.
 
template<class T >
bool ofInsidePoly (const T &p, const std::vector< T > &poly)
 Determine if an glm::vec3 is within the polygon defined by a vector of glm::vec3s.
 

Detailed Description

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(glm::vec2(x,y));
i+=0.005*HALF_PI*0.5;
}
line.close(); // close the shape
int ofGetWidth()
Definition ofAppRunner.cpp:405
int ofGetHeight()
Definition ofAppRunner.cpp:409
#define TWO_PI
Definition ofMathConstants.h:25
#define HALF_PI
Definition ofMathConstants.h:37

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;
}
#define b

ofPolyline also includes methods to get the closest point, determine 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 lineTo() 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 wherever you go next. Storing this position means that you can easily create continuous drawings without difficulty.

Typedef Documentation

◆ ofPolyline

Function Documentation

◆ ofInsidePoly() [1/2]

template<class T >
bool ofInsidePoly ( const T &  p,
const std::vector< T > &  poly 
)

Determine if an glm::vec3 is within the polygon defined by a vector of glm::vec3s.

Parameters
pA point to check.
polyA vector of glm::vec3s defining a polygon.
Returns
True if the glm::vec3 is enclosed, false otherwise.

◆ ofInsidePoly() [2/2]

template<class T >
bool ofInsidePoly ( float  x,
float  y,
const std::vector< T > &  polygon 
)

Determine if an (x,y) coordinate is within the polygon defined by a vector of glm::vec3s.

Parameters
xThe x dimension of the coordinate.
yThe y dimension of the coordinate.
polygona vector of glm::vec3s defining a polygon.
Returns
True if the point defined by the coordinates is enclosed, false otherwise.