bool GfRay::Intersect(const GfPlane &plane, double *distance, bool *frontFacing) const { // The dot product of the ray direction and the plane normal // indicates the angle between them. Reject glancing // intersections. Note: this also rejects ill-formed planes with // zero normals. double d = GfDot(_direction, plane.GetNormal()); if (d < GF_MIN_VECTOR_LENGTH && d > -GF_MIN_VECTOR_LENGTH) return false; // Get a point on the plane. GfVec3d planePoint = plane.GetDistanceFromOrigin() * plane.GetNormal(); // Compute the parametric distance t to the plane. Reject // intersections outside the ray bounds. double t = GfDot(planePoint - _startPoint, plane.GetNormal()) / d; if (t < 0.0) return false; if (distance) *distance = t; if (frontFacing) *frontFacing = (d < 0.0); return true; }
bool GfFrustum::Intersects(const GfBBox3d &bbox) const { if (bbox.GetBox().IsEmpty()) return false; // Recalculate frustum planes if necessary _CalculateFrustumPlanes(); // Get the bbox in its local space and the matrix that converts // world space to that local space. const GfRange3d &localBBox = bbox.GetRange(); const GfMatrix4d &worldToLocal = bbox.GetInverseMatrix(); // Test the bbox against each of the frustum planes, transforming // the plane by the inverse of the matrix to bring it into the // bbox's local space. for (size_t i = 0; i < _planes.size(); i++) { GfPlane localPlane = _planes[i]; localPlane.Transform(worldToLocal); if (! localPlane.IntersectsPositiveHalfSpace(localBBox)) return false; } return true; }
static string _Repr(GfPlane const &self) { return TF_PY_REPR_PREFIX + "Plane(" + TfPyRepr(self.GetNormal()) + ", " + TfPyRepr(self.GetDistanceFromOrigin()) + ")"; }