Segment
Main author: Simon Rohou
The following class provides a reliable representation of a segment.
-
class Segment : public std::array<IntervalVector, 2>
Represents a geometric segment defined by two points enclosed in
IntervalVectors.Inherits from
std::array<IntervalVector, 2>.Public Functions
-
Segment(const std::array<IntervalVector, 2> &x)
Constructs a
Segmentfrom an array of twoIntervalVectors.- Parameters:
x – An array of two
IntervalVectors enclosing the segment endpoints.
-
Segment(const IntervalVector &x1, const IntervalVector &x2)
Constructs a
Segmentfrom twoIntervalVectors.- Parameters:
x1 – The first endpoint \(\mathbf{x}_1\) of the segment.
x2 – The second endpoint \(\mathbf{x}_2\) of the segment.
-
IntervalVector box() const
Computes the bounding box of the segment.
- Returns:
The
IntervalVectorhull box.
-
BoolInterval intersects(const Segment &e) const
Checks whether the segment intersects with another segment.
- Parameters:
e – Another segment.
- Returns:
A
BoolIntervalindicating possible intersection.
-
BoolInterval contains(const IntervalVector &p) const
Checks whether the segment contains a given point.
- Parameters:
p – The point to check, enclosed in a
IntervalVector.- Returns:
A
BoolIntervalindicating possible containment.
-
Segment(const std::array<IntervalVector, 2> &x)
-
IntervalVector codac2::operator&(const Segment &e1, const Segment &e2)
Computes the intersection of two segments.
If the segments do not intersect, an empty
IntervalVectoris returned. If the segments are colinear, the set of intersection points is returned as a box.- Parameters:
e1 – The first segment.
e2 – The second segment.
- Returns:
An
IntervalVectorenclosing the intersection point.
u1,v1 = Segment([[0,0],[2,2]]),Segment([[2,4],[0,6]])
p1 = u1 & v1 # the two segments do not intersect
# p1 == IntervalVector.empty(2)
u2,v2 = Segment([[4,0],[0,4]]),Segment([[2,0],[4,2]])
p2 = u2 & v2
# p2 == IntervalVector([3,1])
u3,v3 = Segment([[1,1],[4,4]]),Segment([[2,2],[5,5]])
p3 = u3 & v3 # the two segments are colinear
# p3 == IntervalVector([[2,4],[2,4]])
Segment u1({{0,0},{2,2}}), v1({{2,4},{0,6}});
auto p1 = u1 & v1; // the two segments do not intersect
// p1 == IntervalVector::empty(2)
Segment u2({{4,0},{0,4}}), v2({{2,0},{4,2}});
auto p2 = u2 & v2;
// p2 == IntervalVector({3,1})
Segment u3({{1,1},{4,4}}), v3({{2,2},{5,5}});
auto p3 = u3 & v3; // the two segments are colinear
// p3 == IntervalVector({{2,4},{2,4}})
-
IntervalVector codac2::proj_intersection(const Segment &e1, const Segment &e2)
Computes the projected intersection of two segments.
This corresponds to the intersection of the two lines related to the two segments. Therefore, the intersection point may not belong to the segments.
If the segments are parallel but not colinear, an empty
IntervalVectoris returned. If the segments are colinear, the set of intersection points is returned as a box.- Parameters:
e1 – The first segment.
e2 – The second segment.
- Returns:
An
IntervalVectorenclosing the intersection point.
u1,v1 = Segment([[0,0],[2,2]]),Segment([[2,4],[0,6]])
p1 = proj_intersection(u1,v1)
# p1 == IntervalVector([3,3])
u2,v2 = Segment([[4,0],[0,4]]),Segment([[2,0],[4,2]])
p2 = proj_intersection(u2,v2)
# p2 == IntervalVector([3,1])
u3,v3 = Segment([[1,1],[4,4]]),Segment([[2,2],[5,5]])
p3 = proj_intersection(u3,v3)
# p3 == IntervalVector([[-oo,oo],[-oo,oo]])
Segment u1({{0,0},{2,2}}), v1({{2,4},{0,6}});
auto p1 = proj_intersection(u1,v1);
// p1 == IntervalVector({3,3})
Segment u2({{4,0},{0,4}}), v2({{2,0},{4,2}});
auto p2 = proj_intersection(u2,v2);
// p2 == IntervalVector({3,1})
Segment u3({{1,1},{4,4}}), v3({{2,2},{5,5}});
auto p3 = proj_intersection(u3,v3);
// p3 == IntervalVector({{-oo,oo},{-oo,oo}})
-
BoolInterval codac2::colinear(const Segment &e1, const Segment &e2)
Checks if two segments are colinear.
- Parameters:
e1 – The first segment.
e2 – The second segment.
- Returns:
A
BoolIntervalindicating possible colinearity.
p1,p2,p3,p4 = [0,0],[1,1],[1.1,1.1],[10,10]
a = colinear(Segment(p1,p2),Segment(p1,p4))
# a == BoolInterval.TRUE
b = colinear(Segment(p1,p3),Segment(p1,p4))
# b == BoolInterval.UNKNOWN (due to floating point uncertainty)
IntervalVector p1({0,0}), p2({1,1}), p3({1.1,1.1}), p4({10,10});
BoolInterval a = colinear(Segment(p1,p2),Segment(p1,p4));
// a == BoolInterval::TRUE
BoolInterval b = colinear(Segment(p1,p3),Segment(p1,p4));
// b == BoolInterval::UNKNOWN (due to floating point uncertainty)