Horizon
Loading...
Searching...
No Matches
Functions
trigo.h File Reference
#include <cmath>
#include <math/vector2d.h>
#include "wx_compat.h"

Go to the source code of this file.

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=nullptr)
 Test if two lines intersect.
 
void RotatePoint (int *pX, int *pY, double angle)
 
void RotatePoint (int *pX, int *pY, int cx, int cy, double angle)
 
void RotatePoint (wxPoint *point, double angle)
 
void RotatePoint (VECTOR2I &point, double angle)
 
void RotatePoint (VECTOR2I &point, const VECTOR2I &centre, double angle)
 
void RotatePoint (wxPoint *point, const wxPoint &centre, double angle)
 
void RotatePoint (double *pX, double *pY, double angle)
 
void RotatePoint (double *pX, double *pY, double cx, double cy, double angle)
 
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 VECTOR2D CalcArcCenter (const VECTOR2D &aStart, const VECTOR2D &aMid, const VECTOR2D &aEnd)
 
const wxPoint CalcArcCenter (const wxPoint &aStart, const wxPoint &aMid, const wxPoint &aEnd)
 
const wxPoint CalcArcCenter (const VECTOR2I &aStart, const VECTOR2I &aEnd, double aAngle)
 
double CalcArcAngle (const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
 Return the subtended angle for a given arc.
 
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.
 
double ArcTangente (int dy, int dx)
 
double EuclideanNorm (const wxPoint &vector)
 Euclidean norm of a 2D vector.
 
double EuclideanNorm (const wxSize &vector)
 
double DistanceLinePoint (const wxPoint &linePointA, const wxPoint &linePointB, const wxPoint &referencePoint)
 Compute the distance between a line and a reference point Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html.
 
bool HitTestPoints (const wxPoint &pointA, const wxPoint &pointB, double threshold)
 Test, if two points are near each other.
 
double CrossProduct (const wxPoint &vectorA, const wxPoint &vectorB)
 Determine the cross product.
 
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.
 
double GetLineLength (const wxPoint &aPointA, const wxPoint &aPointB)
 Return the length of a line segment defined by aPointA and aPointB.
 
double DEG2RAD (double deg)
 
double RAD2DEG (double rad)
 
double DECIDEG2RAD (double deg)
 
double RAD2DECIDEG (double rad)
 
template<class T >
NormalizeAngle360Max (T Angle)
 Normalize angle to be >=-360.0 and <= 360.0 Angle can be equal to -360 or +360.
 
template<class T >
NormalizeAngle360Min (T Angle)
 Normalize angle to be > -360.0 and < 360.0 Angle equal to -360 or +360 are set to 0.
 
template<class T >
NormalizeAngleNeg (T Angle)
 Normalize angle to be in the 0.0 .. -360.0 range: angle is in 1/10 degrees.
 
template<class T >
NormalizeAnglePos (T Angle)
 Normalize angle to be in the 0.0 .. 360.0 range: angle is in 1/10 degrees.
 
template<class T >
void NORMALIZE_ANGLE_POS (T &Angle)
 
double NormalizeAngleDegreesPos (double Angle)
 Normalize angle to be in the 0.0 .. 360.0 range: angle is in degrees.
 
void NORMALIZE_ANGLE_DEGREES_POS (double &Angle)
 
double NormalizeAngleRadiansPos (double Angle)
 
double NormalizeAngleDegrees (double Angle, double aMin, double aMax)
 Normalize angle to be aMin < angle <= aMax angle is in degrees.
 
template<class T , class T2 >
AddAngles (T a1, T2 a2)
 Add two angles (keeping the result normalized). T2 is here.
 
template<class T >
NegateAndNormalizeAnglePos (T Angle)
 
template<class T >
void NEGATE_AND_NORMALIZE_ANGLE_POS (T &Angle)
 
template<class T >
NormalizeAngle90 (T Angle)
 Normalize angle to be in the -90.0 .. 90.0 range.
 
template<class T >
void NORMALIZE_ANGLE_90 (T &Angle)
 
template<class T >
NormalizeAngle180 (T Angle)
 Normalize angle to be in the -180.0 .. 180.0 range.
 
template<class T >
void NORMALIZE_ANGLE_180 (T &Angle)
 
bool InterceptsPositiveX (double aStartAngle, double aEndAngle)
 Test if an arc from aStartAngle to aEndAngle crosses the positive X axis (0 degrees).
 
bool InterceptsNegativeX (double aStartAngle, double aEndAngle)
 Test if an arc from aStartAngle to aEndAngle crosses the negative X axis (180 degrees).
 
double sindecideg (double r, double a)
 Circle generation utility: computes r * sin(a) Where a is in decidegrees, not in radians.
 
double cosdecideg (double r, double a)
 Circle generation utility: computes r * cos(a) Where a is in decidegrees, not in radians.
 

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

◆ CrossProduct()

double CrossProduct ( const wxPoint vectorA,
const wxPoint vectorB 
)
inline

Determine the cross product.

Parameters
vectorATwo-dimensional vector
vectorBTwo-dimensional vector

◆ DistanceLinePoint()

double DistanceLinePoint ( const wxPoint linePointA,
const wxPoint linePointB,
const wxPoint referencePoint 
)
inline

Compute the distance between a line and a reference point Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html.

Parameters
linePointAPoint on line
linePointBPoint on line
referencePointReference point

◆ EuclideanNorm()

double EuclideanNorm ( const wxPoint vector)
inline

Euclidean norm of a 2D vector.

Parameters
vectorTwo-dimensional vector
Returns
Euclidean norm of the vector

◆ GetLineLength()

double GetLineLength ( const wxPoint aPointA,
const wxPoint aPointB 
)
inline

Return the length of a line segment defined by aPointA and aPointB.

See also EuclideanNorm and Distance for the single vector or four scalar versions.

Returns
Length of a line (as double)

◆ HitTestPoints()

bool HitTestPoints ( const wxPoint pointA,
const wxPoint pointB,
double  threshold 
)
inline

Test, if two points are near each other.

Parameters
pointAFirst point
pointBSecond point
thresholdThe maximum distance
Returns
True or false

◆ InterceptsNegativeX()

bool InterceptsNegativeX ( double  aStartAngle,
double  aEndAngle 
)
inline

Test if an arc from aStartAngle to aEndAngle crosses the negative X axis (180 degrees).

Testing is performed in the quadrant 1 to quadrant 4 direction (counter-clockwise).

Parameters
aStartAngleThe arc start angle in degrees.
aEndAngleThe arc end angle in degrees.

◆ InterceptsPositiveX()

bool InterceptsPositiveX ( double  aStartAngle,
double  aEndAngle 
)
inline

Test if an arc from aStartAngle to aEndAngle crosses the positive X axis (0 degrees).

Testing is performed in the quadrant 1 to quadrant 4 direction (counter-clockwise).

Parameters
aStartAngleThe arc start angle in degrees.
aEndAngleThe arc end angle in degrees.

◆ 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