示例#1
0
文件: lineSeg.cpp 项目: 400dama/USD
bool 
GfFindClosestPoints( const GfLine &line, const GfLineSeg &seg,
		     GfVec3d *p1, GfVec3d *p2,
		     double *t1, double *t2 )
{
    GfVec3d cp1, cp2;
    double lt1, lt2;
    if ( !GfFindClosestPoints( line, seg._line,  &cp1, &cp2, &lt1, &lt2 ) )
	return false;

    lt2 = GfClamp( lt2 / seg._length, 0, 1 );
    cp2 = seg.GetPoint( lt2 );

    // If we clamp the line segment, change the rayPoint to be 
    // the closest point on the ray to the clamped point.
    if (lt2 <= 0 || lt2 >= 1){
        cp1 = line.FindClosestPoint(cp2, &lt1);
    }

    if ( p1 )
	*p1 = cp1;

    if ( p2 )
        *p2 = cp2;

    if ( t1 )
	*t1 = lt1;

    if ( t2 )
	*t2 = lt2;

    return true;
}
示例#2
0
文件: ray.cpp 项目: JT-a/USD
GfVec3d
GfRay::FindClosestPoint(const GfVec3d &point, double *rayDistance) const
{
    GfLine l;
    double len = l.Set(_startPoint, _direction);
    double lrd;
    (void) l.FindClosestPoint(point, &lrd);

    if (lrd < 0.0) lrd = 0.0;

    if (rayDistance)
	*rayDistance = lrd / len;

    return l.GetPoint(lrd);
}