Module Gg.P2

2D points.

type t = p2

The type for points.

val dim : int

dim is the dimension of points of type p2.

type mh = m3

The type for matrices representing linear transformations of homogenous 2D space.

Constructors, accessors and constants

val v : float -> float -> p2

v x y is the point (x y).

val x : p2 -> float

x p is the x coordinate of p.

val y : p2 -> float

y p is the y coordinate of p.

val o : p2

o is the point (0 0).

Functions

val mid : p2 -> p2 -> p2

mid p q is the mid point (p + q)/2.

val tr : m3 -> p2 -> p2

tr m p is the affine transform in homogenous 2D space of the point p by m.

Note. Since m is supposed to be affine the function ignores the last row of m. p is treated as a finite point (its last coordinate in homogenous space is 1). Use V2.tr to transform vectors (infinite points).

val orient : p2 -> p2 -> p2 -> float

orient p q r is:

  • > 0. if the sequence p, q, r is in counterclockwise order. r is on the left of the line pq.
  • < 0. if the sequence p, q, r is in clockwise order. r is on the right of line pq.
  • = ±0. if p, q and r are collinear. r is on pq.

This is a port of Jonathan Richard Shewchuk robust orientation predicate.

val orient_fast : p2 -> p2 -> p2 -> float

orient_fast is like orient but faster and less accurate.

The returned magnitude is the signed area of the parallelogram spanned by vectors pr and qr, which is twice the signed area of the triangle pqr.

val seg_inter : ?eps2:float -> p0:p2 -> p1:p2 -> q0:p2 -> q1:p2 -> unit -> [ `None | `Pt of p2 | `Seg of p2 * p2 ]

seg_inter ~p0 ~p1 ~q0 ~q1 () is the intersection between segments p0p1 and q0q1. This is:

  • `None if the segments do not intersect.
  • `Pt i if they intersect on the single point i.
  • `Seg (i0, i1) if they intersect on the segment i0i1.

eps2 is a squared relative epsilon. It is used as a threshold for testing the zeroness of the angle between the segments. Defaults to 1e-8.