SAF
Loading...
Searching...
No Matches
saf_utility_geometry.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Leo McCormack
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
27
28#ifndef SAF_GEOMETRY_H_INCLUDED
29#define SAF_GEOMETRY_H_INCLUDED
30
31#include "saf_utility_misc.h"
32
33#ifdef __cplusplus
34extern "C" {
35#endif /* __cplusplus */
36
38typedef struct _quaternion_data {
39 union {
40 struct { _Atomic_FLOAT32 w;
41 _Atomic_FLOAT32 x;
42 _Atomic_FLOAT32 y;
43 _Atomic_FLOAT32 z;
44 };
45 _Atomic_FLOAT32 Q[4];
46 };
48
57
64typedef struct _voronoi_data{
65 int nVert;
66 int nFaces;
67 float** vert;
68 int** faces;
70
72
73
74/* ========================================================================== */
75/* Basic Geometrical Functions */
76/* ========================================================================== */
77
79void quaternion2rotationMatrix(/* Input Arguments */
81 /* Output Arguments */
82 float R[3][3]);
83
85void rotationMatrix2quaternion(/* Input Arguments */
86 float R[3][3],
87 /* Output Arguments */
89
91void euler2Quaternion(/* Input Arguments */
92 float alpha,
93 float beta,
94 float gamma,
95 int degreesFlag,
97 /* Output Arguments */
99
101void quaternion2euler(/* Input Arguments */
103 int degreesFlag,
105 /* Output Arguments */
106 float* alpha,
107 float* beta,
108 float* gamma);
109
120void euler2rotationMatrix(/* Input Arguments */
121 float alpha,
122 float beta,
123 float gamma,
124 int degreesFlag,
126 /* Output Arguments */
127 float R[3][3]);
128
142void yawPitchRoll2Rzyx (/* Input Arguments */
143 float yaw,
144 float pitch,
145 float roll,
146 int rollPitchYawFLAG,
147 /* Output Arguments */
148 float R[3][3]);
149
158void sph2cart(/* Input Arguments */
159 float* sph,
160 int nDirs,
161 int anglesInDegreesFLAG,
162 /* Output Arguments */
163 float* cart);
164
173void cart2sph(/* Input Arguments */
174 float* cart,
175 int nDirs,
176 int anglesInDegreesFLAG,
177 /* Output Arguments */
178 float* sph);
179
188void unitSph2cart(/* Input Arguments */
189 float* dirs,
190 int nDirs,
191 int anglesInDegreesFLAG,
192 /* Output Arguments */
193 float* dirs_xyz);
194
203void unitCart2sph(/* Input Arguments */
204 float* dirs_xyz,
205 int nDirs,
206 int anglesInDegreesFLAG,
207 /* Output Arguments */
208 float* dirs);
209
218void sphElev2incl(/* Input Arguments */
219 float* dirsElev,
220 int nDirs,
221 int degreesFlag,
222 /* Output Arguments */
223 float* dirsIncl);
224
233void sphIncl2Elev(/* Input Arguments */
234 float* dirsIncl,
235 int nDirs,
236 int degreesFlag,
237 /* Output Arguments */
238 float* dirsElev);
239
241float L2_norm3(float v[3]);
242
244float L2_norm(float* v, int lenV);
245
247float Frob_norm(float* M, int lenX, int lenY);
248
250void crossProduct3(/* Input Arguments */
251 float a[3],
252 float b[3],
253 /* Output Arguments */
254 float c[3]);
255
260float getDistBetweenPointAndLine(/* Input Arguments */
261 float point[3],
262 float v1[3],
263 float v2[3]);
264
266float getDistBetween2Points(/* Input Arguments */
267 float point_a[3],
268 float point_b[3]);
269
270
271/* ========================================================================== */
272/* Computational Geometry Functions */
273/* ========================================================================== */
274
294void convhull3d(/* Input Arguments */
295 const float* vertices,
296 const int nVert,
297 /* Output Arguments */
298 int** faces,
299 int* nFaces);
300
318void convhullnd(/* Input Arguments */
319 const float* points,
320 const int nPoints,
321 const int nd,
322 /* Output Arguments */
323 int** faces,
324 int* nFaces);
325
348void delaunaynd(/* Input Arguments */
349 const float* points,
350 const int nPoints,
351 const int nd,
352 /* Output Arguments */
353 int** DT,
354 int* nDT);
355
367void sphDelaunay(/* Input Arguments */
368 const float* dirs_deg,
369 const int nDirs,
370 /* Output Arguments */
371 int** faces,
372 int* nFaces,
373 float* vertices);
374
384void sphVoronoi(/* Input Arguments */
385 int* faces,
386 int nFaces,
387 float* vertices,
388 int nDirs,
389 /* Output Arguments */
390 voronoi_data* voronoi);
391
398void sphVoronoiAreas(/* Input Arguments */
399 voronoi_data* voronoi,
400 /* Output Arguments */
401 float* areas);
402
416void getVoronoiWeights(/* Input Arguments */
417 float* dirs_deg,
418 int nDirs,
419 int diagFLAG,
420 /* Output Arguments */
421 float* weights);
422
423
424#ifdef __cplusplus
425}/* extern "C" */
426#endif /* __cplusplus */
427
428#endif /* SAF_GEOMETRY_H_INCLUDED */
429 /* doxygen addtogroup Utilities */
void euler2rotationMatrix(float alpha, float beta, float gamma, int degreesFlag, EULER_ROTATION_CONVENTIONS convention, float R[3][3])
Constructs a 3x3 rotation matrix from the Euler angles.
void quaternion2rotationMatrix(quaternion_data *Q, float R[3][3])
Constructs a 3x3 rotation matrix based on a quaternion.
EULER_ROTATION_CONVENTIONS
Available euler2rotationMatrix() conventions.
void convhull3d(const float *vertices, const int nVert, int **faces, int *nFaces)
Builds the convex hull of an arrangement of vertices in 3-dimensional space.
void sphVoronoiAreas(voronoi_data *voronoi, float *areas)
Computes the areas of a Voronoi diagram on the unit sphere [sum(areas)=4pi].
void euler2Quaternion(float alpha, float beta, float gamma, int degreesFlag, EULER_ROTATION_CONVENTIONS convention, quaternion_data *Q)
Converts Euler angles to a quaternion.
void getVoronoiWeights(float *dirs_deg, int nDirs, int diagFLAG, float *weights)
Computes the integration weights, based on the areas of each face of the corresponding Voronoi diagra...
void quaternion2euler(quaternion_data *Q, int degreesFlag, EULER_ROTATION_CONVENTIONS convention, float *alpha, float *beta, float *gamma)
Converts a quaternion to Euler angles.
void sphIncl2Elev(float *dirsIncl, int nDirs, int degreesFlag, float *dirsElev)
Converts spherical coordinates of unit length from inclination to elevation.
void crossProduct3(float a[3], float b[3], float c[3])
Cross product between two 3-element floating point vectors (c = a x b)
void sph2cart(float *sph, int nDirs, int anglesInDegreesFLAG, float *cart)
Converts spherical coordinates to Cartesian coordinates.
void rotationMatrix2quaternion(float R[3][3], quaternion_data *Q)
Calculates the quaternion corresponding to a 3x3 rotation matrix.
void sphElev2incl(float *dirsElev, int nDirs, int degreesFlag, float *dirsIncl)
Converts spherical coordinates of unit length from elevation to inclination.
float getDistBetweenPointAndLine(float point[3], float v1[3], float v2[3])
Returns the distance between a "point" and an infinite line described by the two points "v1" and "v2"...
float Frob_norm(float *M, int lenX, int lenY)
Returns the Frobenius Norm of a matrix M, of dimensions: lenX x lenY.
void sphVoronoi(int *faces, int nFaces, float *vertices, int nDirs, voronoi_data *voronoi)
Computes the Voronoi diagram for a spherical arrangement of points.
void unitSph2cart(float *dirs, int nDirs, int anglesInDegreesFLAG, float *dirs_xyz)
Converts spherical coordinates to Cartesian coordinates of unit length.
void unitCart2sph(float *dirs_xyz, int nDirs, int anglesInDegreesFLAG, float *dirs)
Converts Cartesian coordinates of unit length to spherical coordinates.
void sphDelaunay(const float *dirs_deg, const int nDirs, int **faces, int *nFaces, float *vertices)
Delaunay triangulation of a spherical arrangement of points.
float getDistBetween2Points(float point_a[3], float point_b[3])
Returns the distance between "point_a" and "point_b".
void yawPitchRoll2Rzyx(float yaw, float pitch, float roll, int rollPitchYawFLAG, float R[3][3])
Constructs a 3x3 rotation matrix from the Euler angles, using the yaw-pitch-roll (zyx) convention.
void convhullnd(const float *points, const int nPoints, const int nd, int **faces, int *nFaces)
Builds the convex hull of an arrangement of points in N-dimensional space.
void cart2sph(float *cart, int nDirs, int anglesInDegreesFLAG, float *sph)
Converts Cartesian coordinates to spherical coordinates.
float L2_norm(float *v, int lenV)
Returns the L2 (Euclidean) norm of an arbitrary length vector.
void delaunaynd(const float *points, const int nPoints, const int nd, int **DT, int *nDT)
Computes the Delaunay triangulation of an arrangement of points in N-dimensional space.
float L2_norm3(float v[3])
Returns the L2 (Euclidean) norm of a 3-element vector.
@ EULER_ROTATION_YAW_PITCH_ROLL
yaw-pitch-roll, 'zyx'
@ EULER_ROTATION_ROLL_PITCH_YAW
roll-pitch-yaw, 'xyz'
@ EULER_ROTATION_X_CONVENTION
x-convention, 'zxz'
@ EULER_ROTATION_Y_CONVENTION
y-convention, 'zyz'
A collection of miscellaneous functions.
Quaternion data structure.
_Atomic_FLOAT32 z
Z value of the quaternion [-1..1].
_Atomic_FLOAT32 y
Y value of the quaternion [-1..1].
_Atomic_FLOAT32 x
X value of the quaternion [-1..1].
_Atomic_FLOAT32 w
W value of the quaternion [-1..1].
_Atomic_FLOAT32 Q[4]
WXYZ values of the quaternion [-1..1].
Data structure for Voronoi diagrams.
float ** vert
Vertices; nVert x 3.
int ** faces
faces; nFaces x nPointsPerFace[i]
int nFaces
Number of faces/polygons.
int * nPointsPerFace
Number of points for each face; nFaces x 1.
int nVert
Number of vertices.