ON_BOOL32 ON_Surface::FrameAt( double u, double v, ON_Plane& frame) const { ON_BOOL32 rc = false; ON_3dPoint origin; ON_3dVector udir, vdir, normal; if( EvNormal( u, v, origin, udir, vdir, normal)) { if ( udir.Unitize() ) vdir = ON_CrossProduct( normal, udir); else if ( vdir.Unitize() ) udir = ON_CrossProduct( vdir, normal); frame.CreateFromFrame( origin, udir, vdir); rc = frame.IsValid(); } return rc; }
bool ON_Line::InPlane( ON_Plane& plane, double tolerance ) const { const ON_3dVector v = to-from; const bool bTinyX = fabs(v.x) <= tolerance; const bool bTinyY = fabs(v.y) <= tolerance; const bool bTinyZ = fabs(v.z) <= tolerance; bool rc = true; ON_3dVector X; ON_3dVector Y; if ( bTinyZ && ( !bTinyX || !bTinyY ) ) { X = ON_xaxis; Y = ON_yaxis; } else if ( bTinyX && ( !bTinyY || !bTinyZ ) ) { X = ON_yaxis; Y = ON_zaxis; } else if ( bTinyY && ( !bTinyZ || !bTinyX ) ) { X = ON_zaxis; Y = ON_xaxis; } else { X = v; X.Unitize(); Y.PerpendicularTo(X); if ( bTinyX && bTinyY && bTinyZ ) { rc = false; if ( X.IsZero() ) { X = ON_xaxis; Y = ON_yaxis; } } } plane.CreateFromFrame( from, X, Y ); return rc; }
bool ON_Plane::Morph( const ON_SpaceMorph& morph ) { ON_Plane mp; double s = sqrt( fabs(origin.MaximumCoordinate())*ON_SQRT_EPSILON + ON_ZERO_TOLERANCE ); mp.xaxis = morph.MorphVector(origin,s*xaxis); mp.yaxis = morph.MorphVector(origin,s*yaxis); mp.zaxis = morph.MorphVector(origin,s*zaxis); origin = morph.MorphPoint(origin); UpdateEquation(); bool bx = mp.xaxis.Unitize(); bool by = mp.yaxis.Unitize(); bool bz = mp.zaxis.Unitize(); if (!bx) { mp.xaxis = ON_CrossProduct(mp.yaxis,mp.zaxis); bx = mp.xaxis.Unitize(); } if (!by) { mp.yaxis = ON_CrossProduct(mp.zaxis,mp.xaxis); by = mp.yaxis.Unitize(); } if (!bz) { mp.zaxis = ON_CrossProduct(mp.xaxis,mp.yaxis); bz = mp.zaxis.Unitize(); } mp.origin.Set(0.0,0.0,0.0); mp.UpdateEquation(); bool rc = mp.IsValid(); ON_3dVector x, y, z; if ( rc ) { x = mp.xaxis; y = mp.yaxis; z = mp.zaxis; } else { x = ON_CrossProduct(mp.yaxis,mp.zaxis); y = ON_CrossProduct(mp.zaxis,mp.xaxis); z = ON_CrossProduct(mp.xaxis,mp.yaxis); x.Unitize(); y.Unitize(); z.Unitize(); x = mp.xaxis + x; y = mp.yaxis + y; z = mp.zaxis + z; x.Unitize(); y.Unitize(); z.Unitize(); rc = mp.CreateFromFrame(ON_origin,x,y); if (rc) { x = mp.xaxis; y = mp.yaxis; z = mp.zaxis; } else { rc = mp.CreateFromFrame(ON_origin,y,z); if ( rc ) { y = mp.xaxis; z = mp.yaxis; x = mp.zaxis; } else { rc = mp.CreateFromFrame(ON_origin,z,x); if (rc) { z = mp.xaxis; x = mp.yaxis; y = mp.zaxis; } else { rc = mp.CreateFromNormal(ON_origin,z); if (rc) { x = mp.xaxis; y = mp.yaxis; z = mp.zaxis; } } } } } if (rc) { xaxis = x; yaxis = y; zaxis = z; UpdateEquation(); } return rc; }