Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::RotatedEllipse Class Reference

An ellipse with arbitrary rotation. More...

#include <point.H>

Inheritance diagram for Aleph::RotatedEllipse:
[legend]
Collaboration diagram for Aleph::RotatedEllipse:
[legend]

Classes

struct  ExtremalPoints
 Holds the four axis-extremal points of a rotated ellipse. More...
 

Public Member Functions

 RotatedEllipse (Point center, const Geom_Number &a, const Geom_Number &b, const Geom_Number &cos_theta, const Geom_Number &sin_theta)
 Constructs a rotated ellipse.
 
 RotatedEllipse (Point center, const Geom_Number &a, const Geom_Number &b)
 Constructs an axis-aligned ellipse (rotation angle is 0).
 
 RotatedEllipse ()
 Default constructor.
 
 RotatedEllipse (const RotatedEllipse &)=default
 
RotatedEllipse & operator= (const RotatedEllipse &)=default
 
bool operator== (const RotatedEllipse &e) const noexcept
 Checks for exact equality between two rotated ellipses.
 
bool operator!= (const RotatedEllipse &e) const noexcept
 Checks for inequality between two rotated ellipses.
 
const Point & get_center () const
 Gets the center point.
 
const Geom_Number & get_a () const
 Gets the semi-axis 'a' (local x-axis radius).
 
const Geom_Number & get_b () const
 Gets the semi-axis 'b' (local y-axis radius).
 
const Geom_Number & get_cos () const
 Gets the cosine of the rotation angle.
 
const Geom_Number & get_sin () const
 Gets the sine of the rotation angle.
 
Geom_Number area () const
 Calculates the area of the ellipse.
 
Geom_Number radius_value (const Point &p) const
 Evaluates the ellipse equation for a given point.
 
bool contains (const Point &p) const
 Checks if a point lies inside or on the ellipse.
 
bool strictly_contains (const Point &p) const
 Checks if a point lies strictly inside the ellipse.
 
bool on_boundary (const Point &p) const
 Checks if a point lies exactly on the ellipse boundary.
 
Point sample (const Geom_Number &cos_t, const Geom_Number &sin_t) const
 Samples a point on the ellipse boundary from a parametric angle.
 
Point sample (const Geom_Number &t) const
 Samples a point on the ellipse boundary for a parameter t.
 
bool intersects_with (const Segment &s) const
 Checks if a segment intersects this rotated ellipse.
 
Segment intersection_with (const Segment &s) const
 Computes the intersection segment between s and this ellipse.
 
std::string to_string () const
 
ExtremalPoints extremal_points () const
 Computes the four axis-extremal points of the rotated ellipse.
 
- Public Member Functions inherited from Aleph::Geom_Object
 Geom_Object ()=default
 
virtual ~Geom_Object ()=default
 

Private Member Functions

Point to_local (const Point &p) const
 Transforms a world point to the ellipse's local, unrotated frame.
 
Point to_world (const Point &p) const
 Transforms a point from the ellipse's local frame back to world coordinates.
 
void validate_positive_radii () const
 Validates that semi-axes are positive.
 
void normalize_rotation ()
 Normalizes the rotation (cos, sin) vector to ensure it's a unit vector.
 

Private Attributes

Point center_
 
Geom_Number a_
 
Geom_Number b_
 
Geom_Number cos_th_
 
Geom_Number sin_th_
 

Detailed Description

An ellipse with arbitrary rotation.

Extends the axis-aligned Ellipse by adding a rotation angle. The implicit equation in the rotated frame is:

`((x' - cx)² / a²) + ((y' - cy)² / b²) = 1`

where ‘(x’, y')are coordinates rotated by-θ` around the center.

Since exact trigonometry is often not possible with rational numbers, the rotation is specified by its cosine and sine as exact Geom_Number values. The user is responsible for providing these values.

Definition at line 2472 of file point.H.

Constructor & Destructor Documentation

◆ RotatedEllipse() [1/4]

Aleph::RotatedEllipse::RotatedEllipse ( Point  center,
const Geom_Number &  a,
const Geom_Number &  b,
const Geom_Number &  cos_theta,
const Geom_Number &  sin_theta 
)
inline

Constructs a rotated ellipse.

Parameters
centerThe center point.
aThe semi-axis length along the ellipse's local x-axis.
bThe semi-axis length along the ellipse's local y-axis.
cos_thetaThe cosine of the rotation angle.
sin_thetaThe sine of the rotation angle.

Definition at line 2537 of file point.H.

References normalize_rotation(), and validate_positive_radii().

◆ RotatedEllipse() [2/4]

Aleph::RotatedEllipse::RotatedEllipse ( Point  center,
const Geom_Number &  a,
const Geom_Number &  b 
)
inline

Constructs an axis-aligned ellipse (rotation angle is 0).

Parameters
centerThe center point.
aThe semi-axis length (horizontal radius).
bThe semi-axis length (vertical radius).

Definition at line 2551 of file point.H.

References validate_positive_radii().

◆ RotatedEllipse() [3/4]

Aleph::RotatedEllipse::RotatedEllipse ( )
inline

Default constructor.

Note
Creates a unit circle at the origin with no rotation.

Definition at line 2561 of file point.H.

◆ RotatedEllipse() [4/4]

Aleph::RotatedEllipse::RotatedEllipse ( const RotatedEllipse &  )
default

Member Function Documentation

◆ area()

Geom_Number Aleph::RotatedEllipse::area ( ) const
inline

Calculates the area of the ellipse.

Returns
The area (pi * a * b).

Definition at line 2621 of file point.H.

References a_, b_, Aleph::geom_pi(), and validate_positive_radii().

◆ contains()

bool Aleph::RotatedEllipse::contains ( const Point &  p) const
inline

Checks if a point lies inside or on the ellipse.

Parameters
pThe point to check.
Returns
true if the point is contained.

Definition at line 2646 of file point.H.

References radius_value().

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ extremal_points()

ExtremalPoints Aleph::RotatedEllipse::extremal_points ( ) const
inline

Computes the four axis-extremal points of the rotated ellipse.

Note
These are the points on the ellipse that are most to the right, top, left, and bottom in the world coordinate system.
Returns
An ExtremalPoints struct.

Definition at line 2743 of file point.H.

References a_, b_, Aleph::blossom_maximum_cardinality_matching(), center_, cos_th_, Aleph::Point::get_x(), Aleph::Point::get_y(), sin_th_, Aleph::square_root(), and validate_positive_radii().

Referenced by Aleph::Tikz_Plane::bbox_of(), TEST_F(), and TEST_F().

◆ get_a()

const Geom_Number & Aleph::RotatedEllipse::get_a ( ) const
inline

Gets the semi-axis 'a' (local x-axis radius).

Definition at line 2597 of file point.H.

References a_.

Referenced by Aleph::Tikz_Plane::draw_rotated_ellipse().

◆ get_b()

const Geom_Number & Aleph::RotatedEllipse::get_b ( ) const
inline

Gets the semi-axis 'b' (local y-axis radius).

Definition at line 2602 of file point.H.

References b_.

Referenced by Aleph::Tikz_Plane::draw_rotated_ellipse().

◆ get_center()

const Point & Aleph::RotatedEllipse::get_center ( ) const
inline

Gets the center point.

Definition at line 2592 of file point.H.

References center_.

Referenced by Aleph::Tikz_Plane::draw_rotated_ellipse().

◆ get_cos()

const Geom_Number & Aleph::RotatedEllipse::get_cos ( ) const
inline

Gets the cosine of the rotation angle.

Definition at line 2607 of file point.H.

References cos_th_.

Referenced by Aleph::Tikz_Plane::draw_rotated_ellipse(), and TEST_F().

◆ get_sin()

const Geom_Number & Aleph::RotatedEllipse::get_sin ( ) const
inline

Gets the sine of the rotation angle.

Definition at line 2612 of file point.H.

References sin_th_.

Referenced by Aleph::Tikz_Plane::draw_rotated_ellipse(), and TEST_F().

◆ intersection_with()

Segment Aleph::RotatedEllipse::intersection_with ( const Segment &  s) const
inline

Computes the intersection segment between s and this ellipse.

Parameters
sThe segment to intersect with.
Returns
The intersection Segment. Can be a point for tangency.
Exceptions
std::domain_errorif there is no intersection.

Definition at line 2714 of file point.H.

References a_, b_, Aleph::blossom_maximum_cardinality_matching(), Aleph::Segment::get_src_point(), Aleph::Segment::get_tgt_point(), Aleph::Ellipse::intersection_with(), to_local(), to_world(), and validate_positive_radii().

Referenced by TEST_F().

◆ intersects_with()

bool Aleph::RotatedEllipse::intersects_with ( const Segment &  s) const
inline

Checks if a segment intersects this rotated ellipse.

Parameters
sThe segment to check.
Returns
true if they share at least one point.

Definition at line 2701 of file point.H.

References a_, b_, Aleph::blossom_maximum_cardinality_matching(), Aleph::Segment::get_src_point(), Aleph::Segment::get_tgt_point(), Aleph::Ellipse::intersects_with(), to_local(), and validate_positive_radii().

Referenced by TEST_F().

◆ normalize_rotation()

void Aleph::RotatedEllipse::normalize_rotation ( )
inlineprivate

Normalizes the rotation (cos, sin) vector to ensure it's a unit vector.

Exceptions
std::domain_errorif the rotation vector is (0,0).

Definition at line 2516 of file point.H.

References ah_domain_error_if, cos_th_, sin_th_, and Aleph::square_root().

Referenced by RotatedEllipse().

◆ on_boundary()

bool Aleph::RotatedEllipse::on_boundary ( const Point &  p) const
inline

Checks if a point lies exactly on the ellipse boundary.

Parameters
pThe point to check.
Returns
true if the point is on the boundary.

Definition at line 2666 of file point.H.

References radius_value().

Referenced by TEST_F(), TEST_F(), and TEST_F().

◆ operator!=()

bool Aleph::RotatedEllipse::operator!= ( const RotatedEllipse &  e) const
inlinenoexcept

Checks for inequality between two rotated ellipses.

Parameters
eThe other ellipse.
Returns
true if any parameter is different.

Definition at line 2586 of file point.H.

References Aleph::blossom_maximum_cardinality_matching().

◆ operator=()

RotatedEllipse & Aleph::RotatedEllipse::operator= ( const RotatedEllipse &  )
default

◆ operator==()

bool Aleph::RotatedEllipse::operator== ( const RotatedEllipse &  e) const
inlinenoexcept

Checks for exact equality between two rotated ellipses.

Parameters
eThe other ellipse.
Returns
true if all parameters (center, axes, rotation) are identical.

Definition at line 2575 of file point.H.

References a_, Aleph::and, b_, center_, cos_th_, and sin_th_.

◆ radius_value()

Geom_Number Aleph::RotatedEllipse::radius_value ( const Point &  p) const
inline

Evaluates the ellipse equation for a given point.

Parameters
pThe point in world coordinates.
Returns
A value that is < 1 for interior points, = 1 for boundary points, and > 1 for exterior points.

Definition at line 2633 of file point.H.

References a_, b_, Aleph::blossom_maximum_cardinality_matching(), to_local(), and validate_positive_radii().

Referenced by contains(), on_boundary(), strictly_contains(), and TEST_F().

◆ sample() [1/2]

Point Aleph::RotatedEllipse::sample ( const Geom_Number &  cos_t,
const Geom_Number &  sin_t 
) const
inline

Samples a point on the ellipse boundary from a parametric angle.

Parameters
cos_tThe cosine of the parameter angle t.
sin_tThe sine of the parameter angle t.
Returns
The corresponding Point on the ellipse in world coordinates.

Definition at line 2677 of file point.H.

References a_, b_, Aleph::blossom_maximum_cardinality_matching(), to_world(), and validate_positive_radii().

Referenced by sample(), and TEST_F().

◆ sample() [2/2]

Point Aleph::RotatedEllipse::sample ( const Geom_Number &  t) const
inline

Samples a point on the ellipse boundary for a parameter t.

Parameters
tA parameter in [0, 1], which maps to an angle in [0, 2π).
Returns
The corresponding Point on the ellipse.

Definition at line 2690 of file point.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::cosinus(), Aleph::geom_pi(), sample(), and Aleph::sinus().

◆ strictly_contains()

bool Aleph::RotatedEllipse::strictly_contains ( const Point &  p) const
inline

Checks if a point lies strictly inside the ellipse.

Parameters
pThe point to check.
Returns
true if the point is strictly inside.

Definition at line 2656 of file point.H.

References radius_value().

Referenced by TEST_F().

◆ to_local()

Point Aleph::RotatedEllipse::to_local ( const Point &  p) const
inlineprivate

Transforms a world point to the ellipse's local, unrotated frame.

Parameters
pA point in world coordinates.
Returns
The corresponding point in the ellipse's local coordinate system.

Definition at line 2485 of file point.H.

References center_, cos_th_, Aleph::Point::get_x(), Aleph::Point::get_y(), and sin_th_.

Referenced by intersection_with(), intersects_with(), and radius_value().

◆ to_string()

std::string Aleph::RotatedEllipse::to_string ( ) const
inline

Definition at line 2722 of file point.H.

References a_, b_, center_, cos_th_, Aleph::geom_number_to_double(), sin_th_, and Aleph::Point::to_string().

Referenced by Aleph::operator<<().

◆ to_world()

Point Aleph::RotatedEllipse::to_world ( const Point &  p) const
inlineprivate

Transforms a point from the ellipse's local frame back to world coordinates.

Parameters
pA point in the ellipse's local coordinate system.
Returns
The corresponding point in world coordinates.

Definition at line 2497 of file point.H.

References center_, cos_th_, Aleph::Point::get_x(), Aleph::Point::get_y(), and sin_th_.

Referenced by intersection_with(), and sample().

◆ validate_positive_radii()

void Aleph::RotatedEllipse::validate_positive_radii ( ) const
inlineprivate

Validates that semi-axes are positive.

Exceptions
std::domain_errorif either a_ or b_ is not > 0.

Definition at line 2507 of file point.H.

References a_, ah_domain_error_if, b_, and Aleph::blossom_maximum_cardinality_matching().

Referenced by RotatedEllipse(), RotatedEllipse(), area(), extremal_points(), intersection_with(), intersects_with(), radius_value(), and sample().

Member Data Documentation

◆ a_

◆ b_

◆ center_

Point Aleph::RotatedEllipse::center_
private

Definition at line 2474 of file point.H.

Referenced by extremal_points(), get_center(), operator==(), to_local(), to_string(), and to_world().

◆ cos_th_

Geom_Number Aleph::RotatedEllipse::cos_th_
private

◆ sin_th_

Geom_Number Aleph::RotatedEllipse::sin_th_
private

The documentation for this class was generated from the following file: