My Project
Loading...
Searching...
No Matches
Line Segments

Introduction

In geometry, a line segment is a part of a line that is bounded by two distinct end points, and contains every point on the line between its end points. A closed line segment includes both endpoints.

Line segments can be used to approximate smooth curves.

Line Segment Objects

Creating a spring using an list of segments. See example 13-primitives

Similar to mesh objects, line segment models use vertices to describe all the lines that compose the objects. A finger-proxy algorithm is also used to compute all the interaction forces between the haptic tool and the object. A collision detection must also be initialized after all points have been created.

using namespace chai3d;
// create a line segment object
cMultiSegment* segments = new cMultiSegment();
// add object to world
world->addChild(segments);
// connect some segments to form a spring
double h = 0.0;
double dh = 0.001;
double a = 0.0;
double da = 0.2;
double r = 0.05;
for (int i=0; i<200; i++)
{
double px0 = r * cos(a);
double py0 = r * sin(a);
double pz0 = h;
double px1 = r * cos(a+da);
double py1 = r * sin(a+da);
double pz1 = h+dh;
// create vertex 0
int index0 = segments->newVertex(px0, py0, pz0);
// create vertex 1
int index1 = segments->newVertex(px1, py1, pz1);
// create segment by connecting both vertices together
segments->newSegment(index0, index1);
h = h + dh;
a = a + da;
}
// set haptic properties
segments->m_material->setStiffness(0.5 * maxStiffness);
// assign color properties
cColorf color;
color.setYellowGold();
segments->setLineColor(color);
// assign line width
segments->setLineWidth(4.0);
// use display list for faster rendering
segments->setUseDisplayList(true);
// build collision tree
segments->createAABBCollisionDetector(toolRadius);
virtual void setUseDisplayList(const bool a_useDisplayList, const bool a_affectChildren=false, const bool a_affectComponents=true)
This method enabled or disables the use of a display list for rendering, optionally propagating the o...
Definition CGenericObject.cpp:1511
cMaterialPtr m_material
Material property.
Definition CGenericObject.h:766
This class implements a collection 3D segments.
Definition CMultiSegment.h:97
void setLineWidth(const double a_lineWidth)
This method sets the line width of all segments.
Definition CMultiSegment.h:207
unsigned int newSegment(const unsigned int a_indexVertex0, const unsigned int a_indexVertex1)
This method creates a new segment by passing two vertex indices.
Definition CMultiSegment.cpp:306
unsigned int newVertex(const double a_x=0.0, const double a_y=0.0, const double a_z=0.0)
This method creates a new vertex and adds it to the vertex list.
Definition CMultiSegment.cpp:258
virtual void createAABBCollisionDetector(const double a_radius)
This method builds an AABB collision detector for this mesh.
Definition CMultiSegment.cpp:636
void setLineColor(const cColorf &a_color)
This method sets the color of all segments.
Definition CMultiSegment.cpp:499
Definition CAudioBuffer.cpp:57
This class defines a color using a GLfloat representation for each component.
Definition CColor.h:139
void setYellowGold()
This method sets the color to Gold.
Definition CColor.h:726