FloatPoint TransformationMatrix::projectPoint(const FloatPoint& p) const
{
    // This is basically raytracing. We have a point in the destination
    // plane with z=0, and we cast a ray parallel to the z-axis from that
    // point to find the z-position at which it intersects the z=0 plane
    // with the transform applied. Once we have that point we apply the
    // inverse transform to find the corresponding point in the source
    // space.
    // 
    // Given a plane with normal Pn, and a ray starting at point R0 and
    // with direction defined by the vector Rd, we can find the
    // intersection point as a distance d from R0 in units of Rd by:
    // 
    // d = -dot (Pn', R0) / dot (Pn', Rd)
    
    double x = p.x();
    double y = p.y();
    double z = -(m13() * x + m23() * y + m43()) / m33();

    double outX = x * m11() + y * m21() + z * m31() + m41();
    double outY = x * m12() + y * m22() + z * m32() + m42();

    double w = x * m14() + y * m24() + z * m34() + m44();
    if (w != 1 && w != 0) {
        outX /= w;
        outY /= w;
    }

    return FloatPoint(static_cast<float>(outX), static_cast<float>(outY));
}
const String DOMMatrixReadOnly::toString() const {
  std::stringstream stream;
  if (is2D()) {
    stream << "matrix(" << a() << ", " << b() << ", " << c() << ", " << d()
           << ", " << e() << ", " << f();
  } else {
    stream << "matrix3d(" << m11() << ", " << m12() << ", " << m13() << ", "
           << m14() << ", " << m21() << ", " << m22() << ", " << m23() << ", "
           << m24() << ", " << m31() << ", " << m32() << ", " << m33() << ", "
           << m34() << ", " << m41() << ", " << m42() << ", " << m43() << ", "
           << m44();
  }
  stream << ")";

  return String(stream.str().c_str());
}
Exemple #3
0
bool
CMathGeom3D::
FourPointSphere(double x1, double y1, double z1, double x2, double y2, double z2,
                double x3, double y3, double z3, double x4, double y4, double z4,
                double *xc, double *yc, double *zc, double *r)
{
  double d1 = x1*x1 + y1*y1 + z1*z1;
  double d2 = x2*x2 + y2*y2 + z2*z2;
  double d3 = x3*x3 + y3*y3 + z3*z3;
  double d4 = x4*x4 + y4*y4 + z4*z4;

  CMatrix3DH m11(x1, y1, z1, 1.0, x2, y2, z2, 1.0, x3, y3, z3, 1.0, x4, y4, z4, 1.0);

  double dm11 = m11.determinant();

  if (fabs(dm11) < CMathGen::EPSILON_E6)
    return false;

  double idm11 = 1.0/dm11;

  CMatrix3DH m12(d1, y1, z1, 1.0, d2, y2, z2, 1.0, d3, y3, z3, 1.0, d4, y4, z4, 1.0);

  double dm12 = m12.determinant();

  CMatrix3DH m13(x1, d1, z1, 1.0, x2, d2, z2, 1.0, x3, d3, z3, 1.0, x4, d4, z4, 1.0);

  double dm13 = m13.determinant();

  CMatrix3DH m14(x1, y1, d1, 1.0, x2, y2, d2, 1.0, x3, y3, d3, 1.0, x4, y4, d4, 1.0);

  double dm14 = m14.determinant();

  CMatrix3DH m15(d1, x1, y1, z1, d2, x2, y2, z2, d3, x3, y3, z3, d4, x4, y4, z4);

  double dm15 = m15.determinant();

  *xc = 0.5*dm12*idm11;
  *yc = 0.5*dm13*idm11;
  *zc = 0.5*dm14*idm11;
  *r  = sqrt((*xc)*(*xc) + (*yc)*(*yc) + (*zc)*(*zc) - dm15*idm11);

  return true;
}
Exemple #4
0
CSSFunctionValue* MatrixTransformComponent::toCSSValue() const
{
    CSSFunctionValue* result = CSSFunctionValue::create(m_is2D ? CSSValueMatrix : CSSValueMatrix3d);

    if (m_is2D) {
        double values[6] = {a(), b(), c(), d(), e(), f()};
        for (double value : values) {
            result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number));
        }
    } else {
        double values[16] = {m11(), m12(), m13(), m14(), m21(), m22(), m23(), m24(),
                             m31(), m32(), m33(), m34(), m41(), m42(), m43(), m44()
                            };
        for (double value : values) {
            result->append(cssValuePool().createValue(value, CSSPrimitiveValue::UnitType::Number));
        }
    }

    return result;
}
TransformationMatrix::operator CATransform3D() const
{
    CATransform3D toT3D;
    toT3D.m11 = narrowPrecisionToFloat(m11());
    toT3D.m12 = narrowPrecisionToFloat(m12());
    toT3D.m13 = narrowPrecisionToFloat(m13());
    toT3D.m14 = narrowPrecisionToFloat(m14());
    toT3D.m21 = narrowPrecisionToFloat(m21());
    toT3D.m22 = narrowPrecisionToFloat(m22());
    toT3D.m23 = narrowPrecisionToFloat(m23());
    toT3D.m24 = narrowPrecisionToFloat(m24());
    toT3D.m31 = narrowPrecisionToFloat(m31());
    toT3D.m32 = narrowPrecisionToFloat(m32());
    toT3D.m33 = narrowPrecisionToFloat(m33());
    toT3D.m34 = narrowPrecisionToFloat(m34());
    toT3D.m41 = narrowPrecisionToFloat(m41());
    toT3D.m42 = narrowPrecisionToFloat(m42());
    toT3D.m43 = narrowPrecisionToFloat(m43());
    toT3D.m44 = narrowPrecisionToFloat(m44());
    return toT3D;
}