Exemplo n.º 1
0
// 将本矢量在两个不共线的非零矢量上进行矢量分解, vec = u*uAxis+v*vAxis
bool Vector2d::resolveVector(const Vector2d& uAxis, const Vector2d& vAxis, 
                             Vector2d& uv) const
{
    float denom = uAxis.crossProduct(vAxis);
    if (mgIsZero(denom)) {
        uv.x = 0.f; uv.y = 0.f;
        return false;
    }
    float c = uAxis.crossProduct(*this);
    uv.x = crossProduct(vAxis) / denom;
    uv.y = c / denom;
    return true;
}
Exemplo n.º 2
0
// 将本矢量在两个不共线的非零矢量上进行矢量分解, vec = u*uAxis+v*vAxis
bool Vector2d::resolveVector(const Vector2d& uAxis, const Vector2d& vAxis, 
                             float& u, float& v) const
{
    float denom = uAxis.crossProduct(vAxis);
    if (mgIsZero(denom))
    {
        u = 0.f; v = 0.f;
        return false;
    }
    u = crossProduct(vAxis) / denom;
    v = uAxis.crossProduct(*this) / denom;
    return true;
}
Exemplo n.º 3
0
// 求本矢量投影到矢量xAxis上的垂直距离
// 在xAxis的逆时针方向时返回正值,顺时针则返回负值
float Vector2d::distanceToVector(const Vector2d& xAxis) const
{
    float len = xAxis.length();
    if (len < _MGZERO)
        return length();
    return xAxis.crossProduct(*this) / len;
}
Exemplo n.º 4
0
bool mgcurv::arcTan(
    const Point2d& start, const Point2d& end, const Vector2d& startTan,
    Point2d& center, float& radius,
    float* startAngle, float* sweepAngle)
{
    float a, b, c;
    
    // 弦的中垂线方程系数
    a = end.x - start.x;
    b = end.y - start.y;
    c = -0.5f * (a*(end.x + start.x) + b*(end.y + start.y));
    
    // 求中垂线和切线的交点center
    if (!mglnrel::crossLineAbc(a, b, c, startTan.x, startTan.y, 
        -startTan.x * start.x - startTan.y * start.y, center, Tol::gTol()))
        return false;
    radius = mgHypot(center.x - start.x, center.y - start.y);
    
    if (startAngle && sweepAngle)
    {
        float sa = atan2f(start.y - center.y, start.x - center.x);
        float ea = atan2f(end.y - center.y, end.x - center.x);
        *startAngle = sa;
        if (startTan.crossProduct(start - center) > 0.f)
            *sweepAngle = -mgbase::to0_2PI(sa - ea);
        else
            *sweepAngle = mgbase::to0_2PI(ea - sa);
    }
    
    return true;
}