Easy3D 2.5.3
easy3d::curve Namespace Reference

Algorithms for evaluating curves. More...

Functions

template<typename Point_t >
void quadratic (const Point_t &A, const Point_t &B, const Point_t &C, std::vector< Point_t > &curve, unsigned int bezier_steps=4, bool include_end=false)
 De Casteljau algorithm evaluating a quadratic or conic (second degree) curve from the given control points A, B, and C. Works for both 2D and 3D. More...
 
template<typename Point_t >
void cubic (const Point_t &A, const Point_t &B, const Point_t &C, const Point_t &D, std::vector< Point_t > &curve, unsigned int bezier_steps=4, bool include_end=false)
 De Casteljau algorithm evaluating a cubic (third degree) curve from the given control points A, B, and C. Works for both 2D and 3D. More...
 

Detailed Description

Algorithms for evaluating curves.

Function Documentation

◆ cubic()

void easy3d::curve::cubic ( const Point_t &  A,
const Point_t &  B,
const Point_t &  C,
const Point_t &  D,
std::vector< Point_t > &  curve,
unsigned int  bezier_steps = 4,
bool  include_end = false 
)
inline

De Casteljau algorithm evaluating a cubic (third degree) curve from the given control points A, B, and C. Works for both 2D and 3D.

Parameters
curveReturns the sequence of points on the curve.
bezier_stepsControls the smoothness of the curved corners. A greater value results in a smoother transitions but more vertices. Suggested value is 4.
include_endTure to extend the curve to the end point.

The following code shows how to visualize a quadratic curve (as a polyline):

{
vec3 a(0, 0, 0);
vec3 b(400, 0, 0);
vec3 c(400, 800, 0);
vec3 d(800, 800, 0);
unsigned int steps = 20;
std::vector<vec3> points;
curve::cubic(a, b, c, d, steps, points);
std::cout << "first point: " << points.front() << ", last point: " << points.back() << std::endl;
std::vector<unsigned int> indices;
for (unsigned int i = 0; i < points.size() - 1; ++i) {
indices.push_back(i);
indices.push_back(i + 1);
}
curve->update_vertex_buffer(points);
curve->update_element_buffer(indices);
curve->set_impostor_type(easy3d::LinesDrawable::CYLINDER);
curve->set_line_width(5);
curve->set_uniform_coloring(vec3(0, 1, 0, 1));
viewer.add_drawable(curve);
}
void update_vertex_buffer(const std::vector< vec3 > &vertices, bool dynamic=false)
Creates/Updates a single buffer.
Definition: drawable.cpp:142
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition: drawable_lines.h:40
void set_uniform_coloring(const vec4 &color)
Definition: state.cpp:89
void cubic(const Point_t &A, const Point_t &B, const Point_t &C, const Point_t &D, std::vector< Point_t > &curve, unsigned int bezier_steps=4, bool include_end=false)
De Casteljau algorithm evaluating a cubic (third degree) curve from the given control points A,...
Definition: curve.h:131
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45

◆ quadratic()

void easy3d::curve::quadratic ( const Point_t &  A,
const Point_t &  B,
const Point_t &  C,
std::vector< Point_t > &  curve,
unsigned int  bezier_steps = 4,
bool  include_end = false 
)
inline

De Casteljau algorithm evaluating a quadratic or conic (second degree) curve from the given control points A, B, and C. Works for both 2D and 3D.

Parameters
curveReturns the sequence of points on the curve.
bezier_stepsControls the smoothness of the curved corners. A greater value results in a smoother transitions but more vertices. Suggested value is 4.
include_endTure to extend the curve to the end point.

The following code shows how to visualize a quadratic curve (as a polyline):

{
vec3 a(0, 0, 0);
vec3 b(800, 0, 0);
vec3 c(800, 800, 0);
unsigned int steps = 20;
std::vector<vec3> points;
curve::quadratic(a, b, c, steps, points);
std::cout << "first point: " << points.front() << ", last point: " << points.back() << std::endl;
std::vector<unsigned int> indices;
for (unsigned int i=0; i<points.size() - 1; ++i) {
indices.push_back(i);
indices.push_back(i+1);
}
curve->update_vertex_buffer(points);
curve->update_element_buffer(indices);
curve->set_impostor_type(easy3d::LinesDrawable::CYLINDER);
curve->set_line_width(5);
curve->set_uniform_coloring(vec3(0, 0, 1, 1));
viewer.add_drawable(curve);
}
void quadratic(const Point_t &A, const Point_t &B, const Point_t &C, std::vector< Point_t > &curve, unsigned int bezier_steps=4, bool include_end=false)
De Casteljau algorithm evaluating a quadratic or conic (second degree) curve from the given control p...
Definition: curve.h:79