Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
point_utils.H File Reference

Geometric utilities for 2D points and segments. More...

Go to the source code of this file.

Functions

const Geom_Number area_of_parallelogram (const Point &a, const Point &b, const Point &c)
 Compute signed area of parallelogram formed by three points.
 
const Geom_Number area_of_triangle (const Point &a, const Point &b, const Point &c)
 Compute area of triangle formed by three points.
 
const bool points_are_colinear (const Point &a, const Point &b, const Point &c)
 Test if three points are collinear.
 
const bool c_is_to_left_ (const Point &a, const Point &b, const Point &c)
 Test if point c is strictly left of line a→b.
 
const bool is_clockwise (const Point &a, const Point &b, const Point &c)
 Test if points are in clockwise order.
 
const bool left_on (const Point &a, const Point &b, const Point &c)
 Test if point c is left of or on line a→b.
 
const bool proper_intersection (const Point &a, const Point &b, const Point &c, const Point &d)
 Test for proper segment intersection.
 
const bool between (const Point &a, const Point &b, const Point &c)
 Test if point c is between points a and b.
 
const bool intersect_improp (const Point &a, const Point &b, const Point &c, const Point &d)
 Test for improper (endpoint) segment intersection.
 
const bool intersectp (const Point &a, const Point &b, const Point &c, const Point &d)
 Test if two segments intersect (proper or improper).
 
int read_pixels (ifstream &in)
 Read integer from input stream (pixel coordinates).
 

Detailed Description

Geometric utilities for 2D points and segments.

This file provides functions for computational geometry operations including area calculations, collinearity tests, orientation tests, and segment intersection detection.

Functions

Function Description
area_of_parallelogram Signed area of parallelogram
area_of_triangle Triangle area
points_are_colinear Collinearity test
left_on Left-of-line test
intersectp Segment intersection
See also
point.H Point class
segment.H Segment class
Author
Leandro Rabindranath León

Definition in file point_utils.H.

Function Documentation

◆ area_of_parallelogram()

const Geom_Number area_of_parallelogram ( const Point a,
const Point b,
const Point c 
)
inline

Compute signed area of parallelogram formed by three points.

Uses cross product to compute 2x the signed area of triangle abc. The sign indicates orientation:

  • Positive: a, b, c are counter-clockwise
  • Negative: a, b, c are clockwise
  • Zero: a, b, c are collinear
Parameters
aFirst point
bSecond point
cThird point
Returns
Signed area (2x triangle area)

Definition at line 74 of file point_utils.H.

References Point::get_x(), and Point::get_y().

Referenced by area_of_triangle(), and points_are_colinear().

◆ area_of_triangle()

const Geom_Number area_of_triangle ( const Point a,
const Point b,
const Point c 
)
inline

Compute area of triangle formed by three points.

Parameters
aFirst vertex
bSecond vertex
cThird vertex
Returns
Unsigned area of triangle

Definition at line 90 of file point_utils.H.

References area_of_parallelogram().

◆ between()

const bool between ( const Point a,
const Point b,
const Point c 
)

Test if point c is between points a and b.

Assumes a, b, c are collinear.

Parameters
aFirst endpoint
bSecond endpoint
cPoint to test
Returns
true if c lies on segment ab

Definition at line 190 of file point_utils.H.

References Point::get_x(), and Point::get_y().

Referenced by intersect_improp(), and TEST_F().

◆ c_is_to_left_()

const bool c_is_to_left_ ( const Point a,
const Point b,
const Point c 
)
inline

Test if point c is strictly left of line a→b.

Parameters
aFirst point of line
bSecond point of line
cPoint to test
Returns
true if c is strictly left of a→b

Definition at line 122 of file point_utils.H.

◆ intersect_improp()

const bool intersect_improp ( const Point a,
const Point b,
const Point c,
const Point d 
)

Test for improper (endpoint) segment intersection.

Segments intersect improperly if an endpoint of one lies on the other segment.

Parameters
aFirst endpoint of segment 1
bSecond endpoint of segment 1
cFirst endpoint of segment 2
dSecond endpoint of segment 2
Returns
true if segments intersect at an endpoint

Definition at line 217 of file point_utils.H.

References between().

Referenced by intersectp().

◆ intersectp()

const bool intersectp ( const Point a,
const Point b,
const Point c,
const Point d 
)

Test if two segments intersect (proper or improper).

Returns true if segments ab and cd intersect at any point.

Parameters
aFirst endpoint of segment 1
bSecond endpoint of segment 1
cFirst endpoint of segment 2
dSecond endpoint of segment 2
Returns
true if segments intersect

Definition at line 240 of file point_utils.H.

References intersect_improp().

◆ is_clockwise()

const bool is_clockwise ( const Point a,
const Point b,
const Point c 
)
inline

Test if points are in clockwise order.

Parameters
aFirst point
bSecond point
cThird point
Returns
true if a, b, c are clockwise

Definition at line 135 of file point_utils.H.

◆ left_on()

const bool left_on ( const Point a,
const Point b,
const Point c 
)
inline

Test if point c is left of or on line a→b.

Parameters
aFirst point of line
bSecond point of line
cPoint to test
Returns
true if c is left of or on the line a→b

Definition at line 150 of file point_utils.H.

◆ points_are_colinear()

const bool points_are_colinear ( const Point a,
const Point b,
const Point c 
)
inline

Test if three points are collinear.

Three points are collinear if they lie on the same line.

Parameters
aFirst point
bSecond point
cThird point
Returns
true if points are collinear

Definition at line 107 of file point_utils.H.

References area_of_parallelogram().

◆ proper_intersection()

const bool proper_intersection ( const Point a,
const Point b,
const Point c,
const Point d 
)

Test for proper segment intersection.

Two segments intersect properly if they cross each other's interior (not at endpoints).

Parameters
aFirst endpoint of segment 1
bSecond endpoint of segment 1
cFirst endpoint of segment 2
dSecond endpoint of segment 2
Returns
true if segments intersect properly

Definition at line 167 of file point_utils.H.

◆ read_pixels()

int read_pixels ( ifstream &  in)

Read integer from input stream (pixel coordinates).

Helper function for reading image data.

Parameters
inInput file stream
Returns
Integer value read

Definition at line 260 of file point_utils.H.