VCLib Documentation  6.12.2

Geometry Functions

Geometry Functions

Macros

#define mindiffangle_int(a, b, modulo)
 Minimum Absolute Difference between Two Angles, Fix Point (Macro). More...
 

Functions

F32 Norm (point *a)
 Calculates the Euclidean Length of a Vector. More...
 
F32 AngleP (point *v)
 Calculates the Angle of a Vector. More...
 
F32 PointDistance (point *a, point *b)
 Calculates the Euclidean Distance between Two Points. More...
 
void MidPoint (point *a, point *b, point *out)
 Calculates the Middle between Two Points. More...
 
void VectorDifference (point *a, point *b, point *out)
 Calculates the Vector Difference of Two Points. More...
 
void VectorScale (point *a, F32 scalar, point *out)
 Scales a Vector by a Value. More...
 
void VectorSum (point *a, point *b, point *out)
 Calculates the Vector Sum of Two Points. More...
 
I32 LineIntersection (vcline *a, vcline *b, point *out)
 Calculates the Intersection Point of Two Lines. More...
 
F32 LineAngle (vcline *a, vcline *b)
 Calculates the Angle between Two Lines. More...
 
F32 LineAngle2 (vcline *a, vcline *b)
 Calculates the Angle between Two Lines. More...
 
F32 Angle (vcline *a)
 Calculates the Angle of a Line. More...
 
void LineParallelD (F32 dist, vcline *l, vcline *out)
 Calculates the Line Parallel to l at Distance dist. More...
 
F32 PointLineDistance (point *p, vcline *l)
 Calculates the Distance beween a Point and a Line. More...
 
void PointLineProjection (point *p, vcline *l, point *out)
 Maps Point to nearest Point on Line. More...
 
void LinePerpendicular (point *p, vcline *l, vcline *out)
 Calculates a Line perpendicualar to a given One through a Point. More...
 
void LineParallel (point *p, vcline *l, vcline *out)
 Calculates a Line parallel to a given One through a Point. More...
 
void LineTranslate (point *v, vcline *l, vcline *out)
 Translates a Line parallel by a Vector. More...
 
void LineParameters (point *p1, point *p2, vcline *out)
 Calculates the Line Parameters using Two Points. More...
 
void LineParametersA (point *p, F32 angle, vcline *out)
 Calculates the Line Parameters using a point and an angle. More...
 
void LineFromSlopeInterceptForm (F32 mx, F32 b, vcline *out)
 Calculates a vcline from Line Slope Intercept Form. More...
 
void LineNormal (point *p, F32 angle, vcline *out)
 Calculates the line through the point p perpendicular to angle. More...
 
void affine_point_map (point *p, point *target_p, F32 a[2][2], F32 t[2])
 Affine Transformation of a Point. More...
 
I32 IntersectionPointsN (image *img, vcline *ln, point *p1, point *p2)
 Calculates Two Intersection Points between a Line and the Boundaries of an Image Variable. More...
 
I32 IntersectionPoints (image *a, F32 cx, F32 cy, F32 b, I32 *X0, I32 *Y0, I32 *X1, I32 *Y1)
 Calculates Two Intersection Points between a Line and the Boundaries of an Image Variable. More...
 
I32 IntersectionPointsWithRect (F32 cx, F32 cy, F32 b, F32 xMin, F32 yMin, F32 xMax, F32 yMax, F32 *X0, F32 *Y0, F32 *X1, F32 *Y1)
 Calculates Two Intersection Points between a Line and a Boundary Rectangle. More...
 

Detailed Description

Macro Definition Documentation

◆ mindiffangle_int

#define mindiffangle_int (   a,
  b,
  modulo 
)
Value:
( \
((a)-(b)<0)\
?( min( (modulo) + ((a)-(b)) % (modulo), (((b)-(a)) % (modulo)) )) \
:( min( ((a)-(b)) % (modulo), (modulo) + (((b)-(a)) % (modulo)) )) \
)

The minimum absolute difference between the both given angles is returned modulo the given modulo parameter.

Note
All Parameters must be fix point. Floating point would not work!
Parameters
a,bangles as integer values.
modulomodulo as an integer value.

Function Documentation

◆ Norm()

F32 Norm ( point a)

This function calculates the norm or length of a vector in point representation and returns the result as a float value. The result is given by out = sqrtf(( a->x)² + ( a->y)²).

Returns
the euclidean norm or distance

◆ AngleP()

F32 AngleP ( point v)

This function calculates the angle between the horizontal x-axis and the vector v given in point coordinates and returns the result in radiants.

A value of 0 is output for a horizontal vector pointing right. The result increases for a clockwise rotation up to a value of 2π (360deg) and is always positive.

Returns
angle between x-axis and vector

◆ PointDistance()

F32 PointDistance ( point a,
point b 
)

The function calculates the Euclidean distance between two points and returns the result.

◆ MidPoint()

void MidPoint ( point a,
point b,
point out 
)

The function uses 2 points a and b to calculate the arithmetic middle right inbetween the points and outputs the result in point out.

It is possible to use this function in place, i.e. the pointer out may be identical to either a or b.

◆ VectorDifference()

void VectorDifference ( point a,
point b,
point out 
)

The function calculates the vector difference of two points and returns the result out = a - b.

It is possible to use this function in place, i.e. the pointer out may be identical to either a or b.

◆ VectorScale()

void VectorScale ( point a,
F32  scale,
point out 
)

The function calculates the vector scaled by a given value and returns the result out = a * scale.

It is possible to use this function in place, i.e. the pointer out may be identical to in.

◆ VectorSum()

void VectorSum ( point a,
point b,
point out 
)

The function calculates the vector sum of two points and returns the result out = a + b.

It is possible to use this function in place, i.e. the pointer out may be identical to either a or b.

◆ LineIntersection()

I32 LineIntersection ( vcline a,
vcline b,
point out 
)

This function finds the intersection point of 2 lines given in the standard normal form $ cx * x + cy * y - b = 0 $.

Return values
ERR_SINGULARIf Lines are Parallel.
ERR_NONEOn Success.

◆ LineAngle()

F32 LineAngle ( vcline a,
vcline b 
)

This function calculates the angle between two lines a and b given in vector normal form and returns the result in radiants: A value of 0 is output if both lines are parallel. In all other cases, the result is the angle that line a must be rotated clockwise to be parallel to b. The result increases for a clockwise rotation up to a value of π (180deg) and is always positive.

Returns
angle between line a and line b

◆ LineAngle2()

F32 LineAngle2 ( vcline a,
vcline b 
)

This function calculates the angle between two lines a and b and returns the result in radiants. A value of 0 is output if both lines are parallel. In all other cases, the result is the angle that line a must be rotated clockwise to be parallel to b. In contrast to function LineAngle(), the result covers a full range from -π (-180deg) to +π (180deg) and assumes that the lines are oriented.

◆ Angle()

F32 Angle ( vcline a)

This function calculates the angle between the horizontal x-axis and line a given in vector normal form and returns the result in radiants. A value of 0 is output for a horizontal line. The result increases for a clockwise rotation up to a value of π (180deg) and is always positive.

Returns
angle between x-axis and line

◆ LineParallelD()

void LineParallelD ( F32  dist,
vcline l,
vcline out 
)

calculates the line parallel to l at distance dist larger dist means that the line is more distant to the origin.

It is possible to use this function in place, i.e. the pointer l may be identical to out.

Parameters
distdistance for parallel line
lreference line
outresult line

◆ PointLineDistance()

F32 PointLineDistance ( point p,
vcline l 
)

This function calculates the distance beween a point and a line and returns the result.

◆ PointLineProjection()

void PointLineProjection ( point p,
vcline l,
point out 
)

This function maps a point to a nearest point on a line. Nearest means: The euclidean distance between the points is minimal.

◆ LinePerpendicular()

void LinePerpendicular ( point p,
vcline l,
vcline out 
)

This function calculates a line perpendicualar to a given one through a point. The result is stored in out.

It is possible to use this function in place, i.e. the pointer l may be identical to out.

◆ LineParallel()

void LineParallel ( point p,
vcline l,
vcline out 
)

This function calculates a line parallel to a given one through a point. The result is stored as out.

It is possible to use this function in place, i.e. the pointer l may be identical to out.

◆ LineTranslate()

void LineTranslate ( point v,
vcline l,
vcline out 
)

This function translates a line by a vector given. The result is stored as out.

The line parameters cx and cy must form a vector of norm 1 for this function to work properly.

It is possible to use this function in place, i.e. the pointer l may be identical to out.

◆ LineParameters()

void LineParameters ( point p1,
point p2,
vcline out 
)

This function calculates the line parameters for a line running through the two points p1 and p2. If the two points are too close together, (distance < 5.0e-7), all line parameters will be set to 0.0.

◆ LineParametersA()

void LineParametersA ( point p,
F32  angle,
vcline out 
)

This function calculates the line through the point p with angle angle

Parameters
ppoint for line calculation
angleangle for line calculation, in degree
outresult line

◆ LineFromSlopeInterceptForm()

void LineFromSlopeInterceptForm ( F32  mx,
F32  b,
vcline out 
)

The function transforms a line representation in slope intercept form known as: y = mx * x + b to the more universial representation used by vcline: out->cx * x + out->cy * y - out->b = 0.

Parameters
mx,bSlope Intercept Representation of Line.
outLine in Normal Form.

◆ LineNormal()

void LineNormal ( point p,
F32  angle,
vcline out 
)

This function calculates the line through the point p NORMAL, i.e. perpendicular to angle

Parameters
ppoint for line calculation
angleangle for line calculation, in degree
outresult line

◆ affine_point_map()

void affine_point_map ( point p,
point target_p,
F32  a[2][2],
F32  t[2] 
)
Parameters
pPoint in Original Image (x, y).
target_p(Result) Target Point of p After Affine Transformation.
a2D Transformation Matrix.
t2D Translation Vector.

◆ IntersectionPointsN()

I32 IntersectionPointsN ( image img,
vcline ln,
point p1,
point p2 
)

This function calculates two intersection points between a line and the boundaries of an image variable given. The intersection points are calculated in the following order: Left, Right, Top, Bottom. The line is parameterized as vcline struct.

Parameters
imgPointer to Image Variable.
lnLine.
p1Coordinates of First Intersection Point.
p2Coordinates of Second Intersection Point.
See also
IntersectionPoints().
Return values
ERR_PARAMIf Less than 2 Points Found.
ERR_NONEOn Success.

◆ IntersectionPoints()

I32 IntersectionPoints ( image a,
float  cx,
float  cy,
float  b,
I32 X0,
I32 Y0,
I32 X1,
I32 Y1 
)

This function calculates two intersection points between a line and the boundaries of an image variable given. The intersection points are calculated in the following order: Left, Right, Top, Bottom. The line is parameterized in a normalized vector form as: (cx * x) + (cy * y) - b = 0.

Parameters
aPointer to Image Variable.
cx,cy,bLine Parameters.
X0,Y0Coordinates of First Intersection Point.
X1,Y1Coordinates of Second Intersection Point.
See also
IntersectionPointsN(), IntersectionPointsWithRect().
Return values
ERR_PARAMIf Less than 2 Points Found.
ERR_NONEOn Success.

◆ IntersectionPointsWithRect()

I32 IntersectionPointsWithRect ( float  cx,
float  cy,
float  b,
F32  xMin,
F32  yMin,
F32  xMax,
F32  yMax,
F32 X0,
F32 Y0,
F32 X1,
F32 Y1 
)

This function calculates two intersection points between a line and a boundary rectangle. The intersection points are calculated in the following order: Left, Right, Top, Bottom. The line is parameterized in a normalized vector form as: (cx * x) + (cy * y) - b = 0.

Parameters
xMin,yMin,xMax,yMaxBoundary rectangle.
cx,cy,bLine Parameters.
X0,Y0Coordinates of First Intersection Point.
X1,Y1Coordinates of Second Intersection Point.
See also
IntersectionPoints(), IntersectionPointsN().
Return values
ERR_PARAMIf Less than 2 Points Found.
ERR_NONEOn Success.