本文整理汇总了C++中ON_Line类的典型用法代码示例。如果您正苦于以下问题:C++ ON_Line类的具体用法?C++ ON_Line怎么用?C++ ON_Line使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ON_Line类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ON_IntersectLineLine
bool ON_IntersectLineLine(
const ON_Line& lineA,
const ON_Line& lineB,
double* a,
double* b,
double tolerance,
bool bIntersectSegments
)
{
bool rc = ON_Intersect(lineA,lineB,a,b) ? true : false;
if (rc)
{
if ( bIntersectSegments )
{
if ( *a < 0.0 )
*a = 0.0;
else if ( *a > 1.0 )
*a = 1.0;
if ( *b < 0.0 )
*b = 0.0;
else if ( *b > 1.0 )
*b = 1.0;
}
if ( tolerance > 0.0 )
{
rc = (lineA.PointAt(*a).DistanceTo(lineB.PointAt(*b)) <= tolerance);
}
}
return rc;
}
示例2: ON_Intersect
int ON_Intersect( // returns 0 = no intersections,
// 1 = one intersection,
// 2 = 2 intersections
// If 0 is returned, first point is point
// on line closest to sphere and 2nd point is the point
// on the sphere closest to the line.
// If 1 is returned, first point is obtained by evaluating
// the line and the second point is obtained by evaluating
// the sphere.
const ON_Line& line, const ON_Sphere& sphere,
ON_3dPoint& A, ON_3dPoint& B // intersection point(s) returned here
)
{
int rc = 0;
const ON_3dPoint sphere_center = sphere.plane.origin;
const double sphere_radius = fabs(sphere.radius);
double tol = sphere_radius*ON_SQRT_EPSILON;
if ( tol < ON_ZERO_TOLERANCE )
tol = ON_ZERO_TOLERANCE;
ON_3dPoint line_center = line.ClosestPointTo(sphere_center);
double d = line_center.DistanceTo(sphere_center);
if ( d >= sphere_radius-tol ) {
rc = ( d <= sphere_radius-tol ) ? 1 : 0;
A = line_center;
B = sphere.ClosestPointTo(line_center);
}
else {
d /= sphere_radius;
double h = sphere_radius*sqrt(1.0 - d*d);
ON_3dVector V = line.Direction();
V.Unitize();
A = sphere.ClosestPointTo(line_center - h*V);
B = sphere.ClosestPointTo(line_center + h*V);
d = A.DistanceTo(B);
if ( d <= ON_ZERO_TOLERANCE ) {
A = line_center;
B = sphere.ClosestPointTo(line_center);
rc = 1;
}
else
rc = 2;
}
return rc;
}
示例3: MinimumDistanceTo
double ON_Line::MinimumDistanceTo( const ON_Line& L ) const
{
ON_3dPoint A, B;
double a, b, t, x, d;
bool bCheckA, bCheckB;
bool bGoodX = ON_Intersect(*this,L,&a,&b);
bCheckA = true;
if ( a < 0.0) a = 0.0; else if (a > 1.0) a = 1.0; else bCheckA=!bGoodX;
bCheckB = true;
if ( b < 0.0) b = 0.0; else if (b > 1.0) b = 1.0; else bCheckB=!bGoodX;
A = PointAt(a);
B = L.PointAt(b);
d = A.DistanceTo(B);
if ( bCheckA )
{
L.ClosestPointTo(A,&t);
if (t<0.0) t = 0.0; else if (t > 1.0) t = 1.0;
x = L.PointAt(t).DistanceTo(A);
if ( x < d )
d = x;
}
if ( bCheckB )
{
ClosestPointTo(B,&t);
if (t<0.0) t = 0.0; else if (t > 1.0) t = 1.0;
x = PointAt(t).DistanceTo(B);
if (x < d )
d = x;
}
return d;
}
示例4: switch
bool ON_Mesh::EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const
{
// virtual function default
P = ON_UNSET_POINT;
ON_COMPONENT_INDEX ci = objref.m_component_index;
switch ( ci.m_type )
{
case ON_COMPONENT_INDEX::mesh_vertex:
if ( ci.m_index >= 0 && ci.m_index < m_V.Count() )
P = m_V[ci.m_index];
break;
case ON_COMPONENT_INDEX::meshtop_vertex:
if ( ci.m_index >= 0 && ci.m_index < m_top.m_topv.Count() )
{
const ON_MeshTopologyVertex& topv = m_top.m_topv[ci.m_index];
if ( topv.m_v_count > 0 && topv.m_vi )
{
int vi = topv.m_vi[0];
if ( vi >= 0 && vi < m_V.Count() )
P = m_V[vi];
}
}
break;
case ON_COMPONENT_INDEX::meshtop_edge:
if ( 5 == objref.m_evp.m_t_type
&& fabs(objref.m_evp.m_t[0] + objref.m_evp.m_t[1] - 1.0) <= ON_SQRT_EPSILON )
{
ON_Line L = m_top.TopEdgeLine(ci.m_index);
if ( L.IsValid() )
{
P = L.PointAt(objref.m_evp.m_t[0]);
}
}
break;
case ON_COMPONENT_INDEX::mesh_face:
if ( 4 == objref.m_evp.m_t_type
&& fabs(objref.m_evp.m_t[0] + objref.m_evp.m_t[1] + objref.m_evp.m_t[2] + objref.m_evp.m_t[3] - 1.0) <= ON_SQRT_EPSILON )
{
if ( ci.m_index >= 0 && ci.m_index < m_F.Count() )
{
const int* fvi = m_F[ci.m_index].vi;
if ( fvi[0] < 0 || fvi[0] >= m_V.Count() )
break;
if ( fvi[1] < 0 || fvi[1] >= m_V.Count() )
break;
if ( fvi[2] < 0 || fvi[2] >= m_V.Count() )
break;
if ( fvi[3] < 0 || fvi[3] >= m_V.Count() )
break;
ON_3dPoint V[4];
V[0] = m_V[fvi[0]];
V[1] = m_V[fvi[1]];
V[2] = m_V[fvi[2]];
V[3] = m_V[fvi[3]];
P = objref.m_evp.m_t[0]*V[0] + objref.m_evp.m_t[1]*V[1] + objref.m_evp.m_t[2]*V[2] + objref.m_evp.m_t[3]*V[3];
}
}
break;
default:
// intentionally skipping other ON_COMPONENT_INDEX::TYPE enum values
break;
}
return P.IsValid();
}
示例5: memset
//.........这里部分代码省略.........
{
int i = me.vi0; me.vi0 = me.vi1; me.vi1 = i;
i = me.topvi0; me.topvi0 = me.topvi1; me.topvi1 = i;
}
me_list[me_list_count++] = me;
break;
}
}
}
}
if (me_list_count<1)
{
return false;
}
// Sort me_list[] so edges using same vertices are adjacent
// to each other in the list. This is needed so that non-manifold
// crease edges will be properly collapsed.
ON_qsort(me_list,me_list_count,sizeof(me_list[0]),(QSORTCMPFUNC)CompareMESHEDGE);
// create new vertex or vertices that edge will be
// collapsed to.
mesh.m_C.Destroy();
mesh.m_K.Destroy();
int mei;
bool bHasVertexNormals = mesh.HasVertexNormals();
bool bHasTextureCoordinates = mesh.HasTextureCoordinates();
bool bHasFaceNormals = mesh.HasFaceNormals();
if ( topv0.m_v_count == 1 || topv1.m_v_count == 1 )
{
// a single new vertex
ON_Line Vline(ON_origin,ON_origin);
ON_Line Tline(ON_origin,ON_origin);
ON_3dVector N0(0,0,0);
ON_3dVector N1(0,0,0);
ON_3dPoint P;
int vi, tvi, cnt;
int newvi = topv0.m_vi[0];
cnt = 0;
for ( tvi = 0; tvi < topv0.m_v_count; tvi++ )
{
vi = topv0.m_vi[tvi];
if ( vi < 0 || vi > V_count )
continue;
if ( vi < newvi )
newvi = vi;
cnt++;
P = mesh.m_V[vi];
Vline.from += P;
if ( bHasVertexNormals )
{
N0 += ON_3dVector(mesh.m_N[vi]);
}
if ( bHasTextureCoordinates )
{
P = mesh.m_T[vi];
Tline.from += P;
}
}
if (cnt > 1)
{
示例6: RunCommand
CRhinoCommand::result CCommandSampleCageEdit::RunCommand( const CRhinoCommandContext& context )
{
ON_Workspace ws;
CRhinoCommand::result rc = CRhinoCommand::success;
// Get the captive object
CRhinoGetObject go;
go.SetCommandPrompt( L"Select captive surface or polysurface" );
go.SetGeometryFilter( CRhinoGetObject::surface_object | CRhinoGetObject::polysrf_object );
go.GetObjects( 1, 1 );
rc = go.CommandResult();
if( CRhinoCommand::success != rc )
return rc;
const CRhinoObject* captive = go.Object(0).Object();
if( 0 == captive )
return CRhinoCommand::failure;
// Define the control line
ON_Line line;
CArgsRhinoGetLine args;
rc = RhinoGetLine( args, line );
if( CRhinoCommand::success != rc )
return rc;
// Get the curve parameters
int degree = 3;
int cv_count = 4;
for(;;)
{
CRhinoGetOption gl;
gl.SetCommandPrompt( L"NURBS Parameters" );
gl.AcceptNothing();
int d_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"Degree"), °ree, L"Curve degree", 1.0, 100.0 );
int p_opt = gl.AddCommandOptionInteger( RHCMDOPTNAME(L"PointCount"), &cv_count, L"Number of control points", 2.0, 100.0 );
gl.GetOption();
rc = gl.CommandResult();
if( CRhinoCommand::success != rc )
return rc;
if( CRhinoGet::nothing == gl.Result() )
break;
if( cv_count <= degree )
{
if( CRhinoGet::option != gl.Result() )
continue;
const CRhinoCommandOption* opt = go.Option();
if( 0 == opt )
continue;
if( d_opt == opt->m_option_index )
cv_count = degree + 1;
else
degree = cv_count - 1;
}
}
// Set up morph control
ON_MorphControl* control = new ON_MorphControl();
control->m_varient = 1; // 1= curve
// Specify the source line curve
control->m_nurbs_curve0.Create( 3, false, 2, 2 );
control->m_nurbs_curve0.MakeClampedUniformKnotVector();
control->m_nurbs_curve0.SetCV( 0, line.from );
control->m_nurbs_curve0.SetCV( 1, line.to );
// Specify the destination NURBS curve
control->m_nurbs_curve.Create( 3, false, degree + 1, cv_count );
control->m_nurbs_curve.MakeClampedUniformKnotVector();
double* g = ws.GetDoubleMemory( control->m_nurbs_curve.m_cv_count );
control->m_nurbs_curve.GetGrevilleAbcissae( g );
ON_Interval d = control->m_nurbs_curve.Domain();
double s = 0.0;
int i;
for( i = 0; i < control->m_nurbs_curve.m_cv_count; i++ )
{
s = d.NormalizedParameterAt( g[i] );
control->m_nurbs_curve.SetCV( i, line.PointAt(s) );
}
// Make sure domains match
s = line.Length();
if( s > ON_SQRT_EPSILON )
control->m_nurbs_curve0.SetDomain( 0.0, s );
d = control->m_nurbs_curve0.Domain();
control->m_nurbs_curve.SetDomain( d[0], d[1] );
// Create the morph control object
CRhinoMorphControl* control_object = new CRhinoMorphControl();
control_object->SetControl( control );
context.m_doc.AddObject( control_object );
// Set up the capture
RhinoCaptureObject( control_object, const_cast<CRhinoObject*>(captive) );
// Clean up display
context.m_doc.UnselectAll();
// Turn on the control grips
//.........这里部分代码省略.........
示例7: IsFartherThan
bool ON_Line::IsFartherThan( double d, const ON_Line& L ) const
{
ON_3dPoint A, B;
double a, b, t, x;
bool bCheckA, bCheckB;
a = from.x; if (to.x < a) {b=a; a = to.x;} else b = to.x;
if ( b+d < L.from.x && b+d < L.to.x )
return true;
if ( a-d > L.from.x && a-d > L.to.x )
return true;
a = from.y; if (to.y < a) {b=a; a = to.y;} else b = to.y;
if ( b+d < L.from.y && b+d < L.to.y )
return true;
if ( a-d > L.from.y && a-d > L.to.y )
return true;
a = from.z; if (to.z < a) {b=a; a = to.z;} else b = to.z;
if ( b+d < L.from.z && b+d < L.to.z )
return true;
if ( a-d > L.from.z && a-d > L.to.z )
return true;
if ( !ON_Intersect(*this,L,&a,&b) )
{
// lines are parallel or anti parallel
if ( Direction()*L.Direction() >= 0.0 )
{
// lines are parallel
a = 0.0;
L.ClosestPointTo(from,&b);
// If ( b >= 0.0), then this->from and L(b) are a pair of closest points.
if ( b < 0.0 )
{
// Othersise L.from and this(a) are a pair of closest points.
b = 0.0;
ClosestPointTo(L.from,&a);
}
}
else
{
// lines are anti parallel
a = 1.0;
L.ClosestPointTo(to,&b);
// If ( b >= 0.0), then this->to and L(b) are a pair of closest points.
if ( b < 0.0 )
{
// Othersise L.to and this(a) are a pair of closest points.
b = 0.0;
ClosestPointTo(L.from,&a);
}
}
}
A = PointAt(a);
B = L.PointAt(b);
x = A.DistanceTo(B);
if (x > d)
return true;
bCheckA = true;
if ( a < 0.0) a = 0.0; else if (a > 1.0) a = 1.0; else bCheckA=false;
if (bCheckA )
{
A = PointAt(a);
L.ClosestPointTo(A,&t);
if (t<0.0) t = 0.0; else if (t > 1.0) t = 1.0;
x = L.PointAt(t).DistanceTo(A);
}
bCheckB = true;
if ( b < 0.0) b = 0.0; else if (b > 1.0) b = 1.0; else bCheckB=false;
if ( bCheckB )
{
B = L.PointAt(b);
ClosestPointTo(B,&t);
if (t<0.0) t = 0.0; else if (t > 1.0) t = 1.0;
t = PointAt(t).DistanceTo(B);
if ( bCheckA )
{
if ( t<x ) x = t;
}
else
{
x = t;
}
}
return (x > d);
}
示例8: ON_ArePointsOnLine
int ON_ArePointsOnLine( // returns 0=no, 1 = yes, 2 = pointset is (to tolerance) a single point on the line
int dim, // 2 or 3
int is_rat,
int count,
int stride, const double* point,
const ON_BoundingBox& bbox, // if needed, use ON_GetBoundingBox(dim,is_rat,count,stride,point)
const ON_Line& line, // line to test
double tolerance
)
{
double w;
int i, j, k;
if ( count < 1 )
return 0;
if ( !line.IsValid() )
{
ON_ERROR("line parameter not valid");
return 0;
}
if ( !bbox.IsValid() )
{
ON_ERROR("bbox parameter not valid");
return 0;
}
if ( !ON_IsValid(tolerance) || tolerance < 0.0 )
{
ON_ERROR("tolerance parameter not valid");
return 0;
}
if ( dim < 2 || dim > 3 )
{
ON_ERROR("dim parameter not valid");
return 0;
}
if ( 0 == point )
{
ON_ERROR("point parameter not valid");
return 0;
}
if ( stride < (is_rat?(dim+1):dim) )
{
ON_ERROR("stride parameter not valid");
return 0;
}
int rc = 0;
if ( tolerance == 0.0 ) {
tolerance = bbox.Tolerance();
}
ON_3dPoint Q;
// test bounding box to quickly detect the common coordinate axis cases
rc = (count == 1 || bbox.Diagonal().Length() <= tolerance) ? 2 : 1;
for ( i = 0; rc && i < 2; i++ ) {
Q.x = bbox[i].x;
for ( j = 0; rc && j < 2; j++) {
Q.y = bbox[j].y;
for ( k = 0; rc && k < 2; k++) {
Q.z = bbox[k].z;
if ( Q.DistanceTo( line.ClosestPointTo( Q ) ) > tolerance )
rc = 0;
}
}
}
if ( !rc ) {
// test points one by one
Q.Zero();
rc = (count == 1 || bbox.Diagonal().Length() <= tolerance) ? 2 : 1;
if ( is_rat ) {
for ( i = 0; i < count; i++ ) {
w = point[dim];
if ( w == 0.0 ) {
ON_ERROR("rational point has zero weight");
return 0;
}
ON_ArrayScale( dim, 1.0/w, point, &Q.x );
if ( Q.DistanceTo( line.ClosestPointTo( Q ) ) > tolerance ) {
rc = 0;
break;
}
point += stride;
}
}
else {
for ( i = 0; i < count; i++ ) {
memcpy( &Q.x, point, dim*sizeof(Q.x) );
if ( Q.DistanceTo( line.ClosestPointTo( Q ) ) > tolerance ) {
rc = 0;
break;
}
point += stride;
}
}
}
//.........这里部分代码省略.........
示例9: Transform
ON_BOOL32 MyUserData::Transform( const ON_Xform& xform )
{
// Optional: call the ON_UserData::Transform() if you want the
// ON_UserData::m_userdata_xform value to be updated.
ON_UserData::Transform(xform);
// Transform any geometry you have in your class.
ON_BOOL32 rc = m_my_line.Transform(xform);
return rc;
}