//////////////////////////////////////////////////////////////////////////////////// /// /// \brief This method is used to check if the object intersects with a segment /// in the XY plane. /// /// The zHigh and zLow values are used to eliminate obstacles above or /// below a Z axis threshold of the XY planes. /// /// \param[in] segment The segment to check for collision with. /// \param[in] zHigh The upper boundary in the zPlane for collision detection. /// \param[in] zLow The lower boundary in the zPlane for collision detection. /// /// \return True if there is a collision, otherwise false. /// //////////////////////////////////////////////////////////////////////////////////// bool Line::IsCollisionInXY(const Segment3D& segment, const double zHigh, const double zLow) const { bool result = false; // Translate to XY plane. Segment3D segmentXY1(Point3D(mLine.mPoint1.mX, mLine.mPoint1.mY, 0.0), Point3D(mLine.mPoint2.mX, mLine.mPoint2.mY, 0.0), mLine.mWidth); Segment3D segmentXY2(Point3D(segment.mPoint1.mX, segment.mPoint1.mY, 0.0), Point3D(segment.mPoint2.mX, segment.mPoint2.mY, 0.0), segment.mWidth); BoundingBox bbox = BoundingBox::CreateBoundingBox(mLine); // Check that our object is within the z boundaries. if(bbox.GetTop() >= zLow && bbox.GetBottom() <= zHigh) { // My z value is within the boundaries, so now check if we are // within the distance to the segment. if(Segment3D::GetDistanceToSegment(segmentXY1, segmentXY2) <= 0.0) { result = true; } } return result; }
//////////////////////////////////////////////////////////////////////////////////// /// /// \brief This method is used to check if the object intersects with a triangle /// in the XY plane. /// /// The zHigh and zLow values are used to eliminate obstacles above or /// below a Z axis threshold of the XY planes. /// /// \param[in] p1 A point describing a triangle. /// \param[in] p2 A point describing a triangle. /// \param[in] p3 A point describing a triangle. /// \param[in] zHigh The upper boundary in the zPlane for collision detection. /// \param[in] zLow The lower boundary in the zPlane for collision detection. /// /// \return True if there is a collision, otherwise false. /// //////////////////////////////////////////////////////////////////////////////////// bool Line::IsCollisionInXY(const Point3D& p1, const Point3D& p2, const Point3D& p3, const double zHigh, const double zLow) const { bool result = false; // Translate to the XY plane. Point3D point1XY(p1.mX, p1.mY, 0); Point3D point2XY(p2.mX, p2.mY, 0); Point3D point3XY(p3.mX, p3.mY, 0); Segment3D segmentXY(Point3D(mLine.mPoint1.mX, mLine.mPoint1.mY, 0.0), Point3D(mLine.mPoint2.mX, mLine.mPoint2.mY, 0.0), mLine.mWidth); BoundingBox bbox = BoundingBox::CreateBoundingBox(mLine); // Check that our object is within the z boundaries. if(bbox.GetTop() >= zLow && bbox.GetBottom() <= zHigh) { if(segmentXY.mPoint1.IsInside(point1XY, point2XY, point3XY) || segmentXY.mPoint2.IsInside(point1XY, point2XY, point3XY) ) { result = true; } else { Segment3D edge1(point1XY, point2XY); Segment3D edge2(point2XY, point3XY); Segment3D edge3(point3XY, point1XY); // Check for intersections with edges of the triangle. if(Segment3D::GetDistanceToSegment(segmentXY, edge1) <= 0.0) { result = true; } else if(Segment3D::GetDistanceToSegment(segmentXY, edge2) <= 0.0) { result = true; } else if(Segment3D::GetDistanceToSegment(segmentXY, edge3) <= 0.0) { result = true; } } } return result; }