本文整理汇总了C++中ON_3dVector::Unitize方法的典型用法代码示例。如果您正苦于以下问题:C++ ON_3dVector::Unitize方法的具体用法?C++ ON_3dVector::Unitize怎么用?C++ ON_3dVector::Unitize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ON_3dVector
的用法示例。
在下文中一共展示了ON_3dVector::Unitize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ON_RayShooter_OneSurface
RH_C_FUNCTION int ON_RayShooter_OneSurface(ON_3DPOINT_STRUCT _point, ON_3DVECTOR_STRUCT _direction, const ON_Surface* pConstSurface, ON_SimpleArray<ON_3dPoint>* pPoints, int maxReflections)
{
int rc = 0;
ON_3dPoint point(_point.val[0], _point.val[1], _point.val[2]);
ON_3dVector direction(_direction.val[0], _direction.val[1], _direction.val[2]);
if( pConstSurface && pPoints && maxReflections>0 && point.IsValid() && direction.Unitize() )
{
ON_RayShooter shooter;
ON_X_EVENT hit;
ON_3dPoint Q = point;
ON_3dVector R = direction;
ON_3dVector V[3];
for( int i=0; i<maxReflections; i++ )
{
memset(&hit,0,sizeof(hit));
ON_3dVector T = R;
if( !T.Unitize() )
break;
if( !shooter.Shoot(Q,T,pConstSurface,hit) )
break;
Q = hit.m_A[0];
pPoints->Append(Q);
if( !hit.m_snodeB[0] )
break;
hit.m_snodeB[0]->Evaluate(hit.m_b[0], hit.m_b[1], 1, 3, &V[0].x);
ON_3dVector N = ON_CrossProduct(V[1],V[2]);
if ( !N.Unitize() )
break;
double d = N*T;
R = T + (-2.0*d)*N; // R = reflection direction
}
rc = pPoints->Count();
}
return rc;
}
示例2: CookDerivativesHelper
// Try to make up a 1st derivative if one is zero length
static void CookDerivativesHelper( ON_3dVector& du, ON_3dVector& dv, ON_3dVector& duu, ON_3dVector& duv, ON_3dVector& dvv)
{
bool du_ok = du.LengthSquared() > ON_SQRT_EPSILON;
bool dv_ok = dv.LengthSquared() > ON_SQRT_EPSILON;
if( !du_ok || !dv_ok)
{
ON_3dVector normal;
bool normal_ok = ON_EvNormal( 0, du, dv, duu, duv, dvv, normal ) ? true : false;
if( normal_ok)
normal_ok = normal.LengthSquared() > ON_SQRT_EPSILON;
if( normal_ok)
{
if(( !du_ok) && ( dv_ok && normal_ok))
{
du = ON_CrossProduct( dv, normal);
du_ok = du.Unitize();
du *= (0.00390625*dv.Length());
}
if( du_ok && ( !dv_ok) && normal_ok)
{
dv = ON_CrossProduct( normal, du);
dv_ok = dv.Unitize();
dv *= (0.00390625*du.Length());
}
}
}
}
示例3: ClosestPointTo
ON_3dPoint ON_Torus::ClosestPointTo( ON_3dPoint test_point ) const
{
const ON_Circle major_circle(plane,major_radius);
ON_3dPoint C = major_circle.ClosestPointTo( test_point );
ON_3dVector v = test_point - C;
if ( !v.Unitize() )
{
v = C - plane.origin;
v.Unitize();
}
return C + minor_radius*v;
}
示例4: ClosestPointTo
ON_3dPoint ON_Circle::ClosestPointTo( const ON_3dPoint& point ) const
{
ON_3dPoint P;
ON_3dVector V = plane.ClosestPointTo( point ) - Center();
if ( V.Unitize() ) {
V.Unitize();
P = Center() + Radius()*V;
}
else {
P = PointAt(0.0);
}
return P;
}
示例5: PerpindicularDirection
ON_3dVector ON_Light::PerpindicularDirection() const
{
// returns a consistent vector perpendicular to the
// light's direction. This vector is useful for
// user interface display.
ON_3dVector dir = m_direction;
if ( !dir.IsValid() || !dir.Unitize() )
return ON_UNSET_VECTOR;
ON_3dVector xdir;
if ( IsLinearLight() || IsRectangularLight() )
{
xdir = m_length;
if ( xdir.IsValid() && xdir.Unitize() && fabs(xdir*dir) <= ON_SQRT_EPSILON )
return xdir;
}
if( dir.IsParallelTo( ON_zaxis, ON_DEGREES_TO_RADIANS * 3.0))
xdir = ON_CrossProduct( dir, ON_xaxis);
else
xdir = ON_CrossProduct( dir, ON_zaxis);
xdir.Unitize();
ON_3dVector ydir = ON_CrossProduct(dir,xdir);
ydir.Unitize();
ON_3dVector right;
switch(dir.MaximumCoordinateIndex())
{
case 0:
right = (fabs(xdir.y) > fabs(ydir.y)) ? xdir : ydir;
if ( right.y < 0.0 )
right.Reverse();
break;
case 1:
case 2:
right = (fabs(xdir.x) > fabs(ydir.x)) ? xdir : ydir;
if ( right.x < 0.0 )
right.Reverse();
break;
default:
right = xdir;
break;
}
if ( right[right.MaximumCoordinateIndex()] < 0.0 )
right.Reverse();
return right;
}
示例6: EvSrfTangent
bool ON_PolyEdgeCurve::EvSrfTangent(
double t,
bool bIsoDir,
ON_3dPoint& srfpoint,
ON_3dVector& srftangent,
ON_3dVector& srfnormal
) const
{
ON_3dPoint srfpt;
ON_3dVector du, dv, duu, duv, dvv;
bool rc = EvSrfDerivatives(t,srfpoint,du,dv,duu,duv,dvv);
if (rc )
rc = ON_EvNormal( 0, du, dv, duu, duv, dvv, srfnormal ) ? true : false;
if (rc)
{
int segment_index = SegmentIndex(t);
ON_PolyEdgeSegment* seg = SegmentCurve(segment_index);
if ( seg )
{
if ( bIsoDir && seg->IsoType() == ON_Surface::not_iso )
bIsoDir = false;
ON_3dVector crvtangent = TangentAt(t);
ON_3dVector binormal = ON_CrossProduct(crvtangent,srfnormal);
binormal.Unitize();
if ( seg->ReversedTrimDir() )
binormal.Reverse();
// at this point, binormal points "out" and is tangent
// to the surface.
if ( bIsoDir )
{
du.Unitize();
dv.Unitize();
double B_dot_du = binormal*du;
double B_dot_dv = binormal*dv;
if ( fabs(B_dot_dv) > fabs(B_dot_du) )
{
if (B_dot_dv < 0.0)
dv.Reverse();
srftangent = dv;
}
else
{
if (B_dot_du < 0.0)
du.Reverse();
srftangent = du;
}
}
else
srftangent = binormal;
if ( seg && seg->m_face && seg->m_face->m_bRev )
srfnormal.Reverse();
}
else
rc = false;
}
return rc;
}
示例7: TangentAt
ON_3dVector ON_Ellipse::TangentAt(
double t // parameter
) const
{
ON_3dVector T = DerivativeAt( 1, t );
T.Unitize();
return T;
}
示例8: GetRotation
bool ON_Quaternion::GetRotation(double& angle, ON_3dVector& axis) const
{
const double s = Length();
angle = (s > ON_DBL_MIN) ? 2.0*acos(a/s) : 0.0;
axis.x = b;
axis.y = c;
axis.z = d;
return (axis.Unitize() && s > ON_DBL_MIN);
}
示例9: arbaxis
void arbaxis(const ON_3dVector& givenaxis, ON_3dVector& newaxis)
{
if(fabs(givenaxis[0]) < ARBBOUND && fabs(givenaxis[1]) < ARBBOUND) // near world z
newaxis = ON_CrossProduct(ON_yaxis, givenaxis);
else
newaxis = ON_CrossProduct(ON_zaxis, givenaxis);
newaxis.Unitize();
}
示例10:
static double Angle3d(const ON_3dVector& axis, ON_3dVector& from, const ON_3dVector& to)
{
ON_3dVector x = from, a = to;
x.Unitize();
a.Unitize();
ON_3dVector y = ON_CrossProduct(axis, from);
y.Unitize();
double cosa = x * a;
if(cosa > 1.0 - ON_SQRT_EPSILON)
return 0.0;
if(cosa < ON_SQRT_EPSILON - 1.0)
return ON_PI;
double sina = a * y;
return atan2(sina, cosa);
}
示例11: ClosestPointTo
bool ON_Cone::ClosestPointTo(
ON_3dPoint point,
double* radial_parameter,
double* height_parameter
) const
{
// untested code
bool rc = false;
ON_3dVector v = (point-plane.origin);
double x = v*plane.xaxis;
double y = v*plane.yaxis;
double z = v*plane.zaxis;
if ( radial_parameter )
{
double a = ( 0.0 == y && 0.0 == x ) ? 0.0 : atan2(y,x);
if (a > 2.0*ON_PI )
{
a -= 2.0*ON_PI;
}
if (a < 0.0 )
{
a += 2.0*ON_PI;
}
*radial_parameter = a;
}
if (height_parameter)
{
point.x -= plane.origin.x;
point.y -= plane.origin.y;
point.z -= plane.origin.z;
v.x = x;
v.y = y;
v.z = 0.0;
v.Unitize();
v.x *= radius;
v.y *= radius;
ON_Line line(ON_origin, v.x*plane.xaxis + v.y*plane.yaxis + height*plane.zaxis );
rc = line.ClosestPointTo(point,&z);
if (rc)
{
*height_parameter = z*height;
}
}
return rc;
}
示例12: NormalAt
ON_3dVector ON_Cone::NormalAt( double radial_parameter, double height_parameter ) const
{
double s = sin(radial_parameter);
double c = cos(radial_parameter);
if ( radius<0.) {
c = -c;
s = -s;
}
ON_3dVector ds = c*plane.yaxis - s*plane.xaxis;
ON_3dVector N = ON_CrossProduct( ((radius<0.0)?-ds:ds),
plane.PointAt(radius*c,radius*s,height) - plane.origin
);
N.Unitize();
return N;
}
示例13:
RH_C_FUNCTION ON_AngularDimension2* ON_AngularDimension2_New(ON_Arc* arc, double offset)
{
ON_AngularDimension2* rc = NULL;
if( arc )
{
rc = new ON_AngularDimension2();
ON_3dVector v = arc->StartPoint()-arc->Center();
v.Unitize();
ON_3dPoint apex = arc->Center();
ON_3dPoint p0 = arc->StartPoint();
ON_3dPoint p1 = arc->EndPoint();
ON_3dPoint arc_pt = p0 + ( v * offset );
ON_3dVector normal = arc->Normal();
rc->CreateFromPoints(apex, p0, p1, arc_pt, normal);
}
return rc;
}
示例14: 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;
}
示例15: InPlane
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;
}