//-------------------------------------------------------------------------------------------------- /// Get the normal of the plane /// /// The normal may not be normalized //-------------------------------------------------------------------------------------------------- Vec3d Plane::normal() const { Vec3d normal = Vec3d(m_A, m_B, m_C); CVF_ASSERT(!normal.isZero()); return normal; }
//-------------------------------------------------------------------------------------------------- /// Compute the plane equation from the given point and normal /// /// \param point Point on the plane /// \param normal The plane's normal //-------------------------------------------------------------------------------------------------- bool Plane::setFromPointAndNormal(const Vec3d& point, const Vec3d& normal) { if (normal.isZero()) return false; m_A = normal.x(); m_B = normal.y(); m_C = normal.z(); m_D = -(normal*point); return true; }
//-------------------------------------------------------------------------------------------------- /// Compute the plane equation from the given three points /// /// \param p1 First point on the plane /// \param p2 Second point on the plane /// \param p3 Third point on the plane /// /// \return true if successfully set. false if points are on the same line. /// /// The three points must be different from each other and cannot be on the same line in space //-------------------------------------------------------------------------------------------------- bool Plane::setFromPoints(const Vec3d& p1, const Vec3d& p2, const Vec3d& p3) { Vec3d v1 = p2 - p1; Vec3d v2 = p3 - p1; Vec3d normal = v1 ^ v2; if (normal.isZero()) return false; setFromPointAndNormal(p1, normal); return true; }