Horizon
Loading...
Searching...
No Matches
Functions
trigo.cpp File Reference

Trigonometric and geometric basic functions. More...

#include <limits>
#include <stdlib.h>
#include <type_traits>
#include <geometry/seg.h>
#include <math/util.h>
#include <math/vector2d.h>
#include <trigo.h>

Functions

bool IsPointOnSegment (const wxPoint &aSegStart, const wxPoint &aSegEnd, const wxPoint &aTestPoint)
 Test if aTestPoint is on line defined by aSegStart and aSegEnd.
 
bool SegmentIntersectsSegment (const wxPoint &a_p1_l1, const wxPoint &a_p2_l1, const wxPoint &a_p1_l2, const wxPoint &a_p2_l2, wxPoint *aIntersectionPoint)
 Test if two lines intersect.
 
bool TestSegmentHit (const wxPoint &aRefPoint, const wxPoint &aStart, const wxPoint &aEnd, int aDist)
 Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
 
const VECTOR2I CalcArcMid (const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle)
 Return the middle point of an arc, half-way between aStart and aEnd.
 
double ArcTangente (int dy, int dx)
 
void RotatePoint (int *pX, int *pY, double angle)
 
void RotatePoint (int *pX, int *pY, int cx, int cy, double angle)
 
void RotatePoint (wxPoint *point, const wxPoint &centre, double angle)
 
void RotatePoint (VECTOR2I &point, const VECTOR2I &centre, double angle)
 
void RotatePoint (double *pX, double *pY, double cx, double cy, double angle)
 
void RotatePoint (double *pX, double *pY, double angle)
 
const wxPoint CalcArcCenter (const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle)
 
const VECTOR2D CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd)
 
const VECTOR2I CalcArcCenter (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
 Determine the center of an arc or circle given three points on its circumference.
 
const wxPoint CalcArcCenter (const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
 
double CalcArcAngle (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
 Return the subtended angle for a given arc.
 

Detailed Description

Trigonometric and geometric basic functions.

Function Documentation

◆ CalcArcCenter()

const VECTOR2I CalcArcCenter ( const VECTOR2I aStart,
const VECTOR2I aMid,
const VECTOR2I aEnd 
)

Determine the center of an arc or circle given three points on its circumference.

Parameters
aStartThe starting point of the circle (equivalent to aEnd)
aMidThe point on the arc, half-way between aStart and aEnd
aEndThe ending point of the circle (equivalent to aStart)
Returns
The center of the circle

◆ CalcArcMid()

const VECTOR2I CalcArcMid ( const VECTOR2I aStart,
const VECTOR2I aEnd,
const VECTOR2I aCenter,
bool  aMinArcAngle = true 
)

Return the middle point of an arc, half-way between aStart and aEnd.

There are two possible solutions which can be found by toggling aMinArcAngle. The behaviour is undefined for semicircles (i.e. 180 degree arcs).

Parameters
aStartThe starting point of the arc (for calculating the radius)
aEndThe end point of the arc (for determining the arc angle)
aCenterThe center point of the arc
aMinArcAngleIf true, returns the point that results in the smallest arc angle.
Returns
The middle point of the arc

◆ IsPointOnSegment()

bool IsPointOnSegment ( const wxPoint aSegStart,
const wxPoint aSegEnd,
const wxPoint aTestPoint 
)

Test if aTestPoint is on line defined by aSegStart and aSegEnd.

This function is faster than TestSegmentHit() because aTestPoint should be exactly on the line. This works fine only for H, V and 45 degree line segments.

Parameters
aSegStartThe first point of the line segment.
aSegEndThe second point of the line segment.
aTestPointThe point to test.
Returns
true if the point is on the line segment.

◆ SegmentIntersectsSegment()

bool SegmentIntersectsSegment ( const wxPoint a_p1_l1,
const wxPoint a_p2_l1,
const wxPoint a_p1_l2,
const wxPoint a_p2_l2,
wxPoint aIntersectionPoint = nullptr 
)

Test if two lines intersect.

Parameters
a_p1_l1The first point of the first line.
a_p2_l1The second point of the first line.
a_p1_l2The first point of the second line.
a_p2_l2The second point of the second line.
aIntersectionPointis filled with the intersection point if it exists
Returns
bool - true if the two segments defined by four points intersect. (i.e. if the 2 segments have at least a common point)

◆ TestSegmentHit()

bool TestSegmentHit ( const wxPoint aRefPoint,
const wxPoint aStart,
const wxPoint aEnd,
int  aDist 
)

Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.

Parameters
aRefPoint= reference point to test
aStartis the first end-point of the line segment
aEndis the second end-point of the line segment
aDist= maximum distance for hit