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
28#ifndef SAF_GEOMETRY_H_INCLUDED
29#define SAF_GEOMETRY_H_INCLUDED
30
31#ifdef __cplusplus
32extern "C" {
33#endif /* __cplusplus */
34
36typedef struct _quaternion_data {
37 union {
38 struct { float w;
39 float x;
40 float y;
41 float z;
42 };
43 float Q[4];
44 };
46
55
62typedef struct _voronoi_data{
63 int nVert;
64 int nFaces;
65 float** vert;
66 int** faces;
70
71
72/* ========================================================================== */
73/* Basic Geometrical Functions */
74/* ========================================================================== */
75
77void quaternion2rotationMatrix(/* Input Arguments */
79 /* Output Arguments */
80 float R[3][3]);
81
83void rotationMatrix2quaternion(/* Input Arguments */
84 float R[3][3],
85 /* Output Arguments */
87
89void euler2Quaternion(/* Input Arguments */
90 float alpha,
91 float beta,
92 float gamma,
93 int degreesFlag,
95 /* Output Arguments */
97
99void quaternion2euler(/* Input Arguments */
101 int degreesFlag,
103 /* Output Arguments */
104 float* alpha,
105 float* beta,
106 float* gamma);
107
118void euler2rotationMatrix(/* Input Arguments */
119 float alpha,
120 float beta,
121 float gamma,
122 int degreesFlag,
124 /* Output Arguments */
125 float R[3][3]);
126
140void yawPitchRoll2Rzyx (/* Input Arguments */
141 float yaw,
142 float pitch,
143 float roll,
144 int rollPitchYawFLAG,
145 /* Output Arguments */
146 float R[3][3]);
147
156void sph2cart(/* Input Arguments */
157 float* sph,
158 int nDirs,
159 int anglesInDegreesFLAG,
160 /* Output Arguments */
161 float* cart);
162
171void cart2sph(/* Input Arguments */
172 float* cart,
173 int nDirs,
174 int anglesInDegreesFLAG,
175 /* Output Arguments */
176 float* sph);
177
186void unitSph2cart(/* Input Arguments */
187 float* dirs,
188 int nDirs,
189 int anglesInDegreesFLAG,
190 /* Output Arguments */
191 float* dirs_xyz);
192
201void unitCart2sph(/* Input Arguments */
202 float* dirs_xyz,
203 int nDirs,
204 int anglesInDegreesFLAG,
205 /* Output Arguments */
206 float* dirs);
207
216void sphElev2incl(/* Input Arguments */
217 float* dirsElev,
218 int nDirs,
219 int degreesFlag,
220 /* Output Arguments */
221 float* dirsIncl);
222
231void sphIncl2Elev(/* Input Arguments */
232 float* dirsIncl,
233 int nDirs,
234 int degreesFlag,
235 /* Output Arguments */
236 float* dirsElev);
237
239float L2_norm3(float v[3]);
240
242float L2_norm(float* v, int lenV);
243
245float Frob_norm(float* M, int lenX, int lenY);
246
248void crossProduct3(/* Input Arguments */
249 float a[3],
250 float b[3],
251 /* Output Arguments */
252 float c[3]);
253
258float getDistBetweenPointAndLine(/* Input Arguments */
259 float point[3],
260 float v1[3],
261 float v2[3]);
262
264float getDistBetween2Points(/* Input Arguments */
265 float point_a[3],
266 float point_b[3]);
267
268
269/* ========================================================================== */
270/* Computational Geometry Functions */
271/* ========================================================================== */
272
292void convhull3d(/* Input Arguments */
293 const float* vertices,
294 const int nVert,
295 /* Output Arguments */
296 int** faces,
297 int* nFaces);
298
316void convhullnd(/* Input Arguments */
317 const float* points,
318 const int nPoints,
319 const int nd,
320 /* Output Arguments */
321 int** faces,
322 int* nFaces);
323
346void delaunaynd(/* Input Arguments */
347 const float* points,
348 const int nPoints,
349 const int nd,
350 /* Output Arguments */
351 int** DT,
352 int* nDT);
353
365void sphDelaunay(/* Input Arguments */
366 const float* dirs_deg,
367 const int nDirs,
368 /* Output Arguments */
369 int** faces,
370 int* nFaces,
371 float* vertices);
372
382void sphVoronoi(/* Input Arguments */
383 int* faces,
384 int nFaces,
385 float* vertices,
386 int nDirs,
387 /* Output Arguments */
388 voronoi_data* voronoi);
389
396void sphVoronoiAreas(/* Input Arguments */
397 voronoi_data* voronoi,
398 /* Output Arguments */
399 float* areas);
400
414void getVoronoiWeights(/* Input Arguments */
415 float* dirs_deg,
416 int nDirs,
417 int diagFLAG,
418 /* Output Arguments */
419 float* weights);
420
421
422#ifdef __cplusplus
423}/* extern "C" */
424#endif /* __cplusplus */
425
426#endif /* SAF_GEOMETRY_H_INCLUDED */
427
428 /* 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'
Quaternion data structure.
float x
X value of the quaternion [-1..1].
float z
Z value of the quaternion [-1..1].
float y
Y value of the quaternion [-1..1].
float w
W value 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.