Segments

Contruction

class Segment2D(A, B)

Create a segment \([AB]\), where A and B can be either Point2D or tuple (x,y).

Read-write attributes

A: Point2D
B: Point2D

Segment Points. They may be replaced by another points, for example:

AB.A = Point2D(1, 2)

or coordinate may be changed inplace, for example:

AB.A.y = -2

Read only attributes

area: length

Segment length \(|AB|\)

Methods

In either case, the method recompute() must be called after change(s).

recompute(self)

Recompute segment property (length, vector). Must be called when a segment point is changed, or its coordinate is chanded.

Structures

CSegment2D
CPoint2D* A

\(A\) is the first segment point.

CPoint2D* B

\(B\) is the second segment point.

Note

CSegment2D represents a segment by two points. A segment may also be represented by a point and a vector. There is no C structure that represent a segment this way. If needed by a function, a Point2D and a Vector2D must be passed explicitly. See for example segment2d_where.

CSegment2D* new_segment2d()

Allocate a new CSegment2D.

This do not allocate members A, B.

void del_segment2d(CSegment2D* csegment2d)

Delete a CSegment2D.

This do not delete members A, B.

void segment2d_set(CSegment2D* AB, CPoint2D* A, CPoint2D* B)

Set members A and B.

Computational functions

double segment2d_distance_point2d(CSegment2D* AB, CVector2D* u, CPoint2D* P)

Compute distance of a point \(P\) to the segment \([AB]\).

\(\mathbf{u}\) is the vector from \(A\) to \(A\).

double segment2d_square_distance_point2d(CSegment2D* AB, CVector2D* u, CPoint2D* P)

Compute distance of a point \(P\) to the segment \([AB]\).

\(\mathbf{u}\) is the vector from \(A\) to \(A\).

Sometime, the knowledge of the square distance is enough, and for performance, computing the square root can be avoided.

double segment2d_where(CPoint2D* A, CVector2D* AB, CPoint2D* P)

Compute \(\alpha\) such as \(P = A + \alpha \mathbf{AB}\).

This assumes point \(P\) in on line \((AB)\).

void segment2d_middle(CPoint2D* M, CSegment2D* AB)

Compute the point \(M\), middle of the segment \([AB]\).

In [ ]: