示例#1
0
void R2Vector::Project(const R2Vector& vector)
{
    // Project onto another vector    
    double dot = Dot(vector);
    double length = vector.Length();
    if (length != 0) dot /= (length * length);
    *this = vector * dot;
}
示例#2
0
RNLength R2Distance(const R2Point& point, const R2Ray& ray)
{
    // Check if start point is closest
    R2Vector v = point - ray.Start();
    RNScalar dir = v.Dot(ray.Vector());
    if (RNIsNegative(dir)) return v.Length();

    // Return distance from point to ray line
    return R2Distance(point, ray.Line());
}
示例#3
0
RNLength R2Distance(const R2Point& point1, const R2Point& point2)
{
    // Return length of vector between points
    R2Vector v = point1 - point2;
    return v.Length();
}