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 Segment from an array of two IntervalVectors.

Parameters:

x – An array of two IntervalVectors enclosing the segment endpoints.

Segment(const IntervalVector &x1, const IntervalVector &x2)

Constructs a Segment from two IntervalVectors.

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 IntervalVector hull box.

BoolInterval intersects(const Segment &e) const

Checks whether the segment intersects with another segment.

Parameters:

e – Another segment.

Returns:

A BoolInterval indicating 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 BoolInterval indicating possible containment.

bool operator==(const Segment &p) const

Comparison operator.

Equality means that boxes enclosing the endpoints are strictly equal.

Parameters:

p – Another segment.

Returns:

True if both segments are equal.

IntervalVector codac2::operator&(const Segment &e1, const Segment &e2)

Computes the intersection of two segments.

If the segments do not intersect, an empty IntervalVector is 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 IntervalVector enclosing 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]])
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 IntervalVector is 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 IntervalVector enclosing 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]])
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 BoolInterval indicating 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)