libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
geom.h File Reference
#include <stdlib.h>
#include <math.h>
#include "sysmacros.h"
#include "types.h"
Include dependency graph for geom.h:

Go to the source code of this file.

Data Structures

struct  geo_pos3_t
 
struct  geo_pos2_t
 
struct  geo_pos3_32_t
 
struct  geo_pos2_32_t
 
struct  vect3_t
 
struct  vect3l_t
 
struct  vect2_t
 
struct  ellip_t
 
struct  bezier_t
 
struct  sph_xlate_t
 
struct  fpp_t
 
struct  lcc_t
 
struct  mat4_t
 
struct  mat3_t
 

Macros

#define RAD2DEG_RATIO   (M_PI / 180.0)
 
#define DEG2RAD_RATIO   (180.0 / M_PI)
 
#define DEG2RAD(d)   ((d) * RAD2DEG_RATIO)
 
#define RAD2DEG(r)   ((r) * DEG2RAD_RATIO)
 
#define GEO_POS2(lat, lon)   ((geo_pos2_t){(lat), (lon)})
 
#define GEO_POS3(lat, lon, elev)   ((geo_pos3_t){(lat), (lon), (elev)})
 
#define GEO_POS3_F32(lat, lon, elev)   ((geo_pos3_f32_t){(lat), (lon), (elev)})
 
#define GEO_POS2_F32(lat, lon)   ((geo_pos2_f32_t){(lat), (lon)})
 
#define TO_GEO3(geo3)    ((geo_pos3_t){(geo3).lat, (geo3).lon, (geo3).elev})
 
#define TO_GEO2(geo2)    ((geo_pos2_t){(geo2).lat, (geo2).lon})
 
#define TO_GEO3_32(geo3)    ((geo_pos3_32_t){(geo3).lat, (geo3).lon, (geo3).elev})
 
#define TO_GEO2_32(geo2)    ((geo_pos3_32_t){(geo3).lat, (geo3).lon})
 
#define VECT2(x, y)   ((vect2_t){(x), (y)})
 
#define VECT3(x, y, z)   ((vect3_t){(x), (y), (z)})
 
#define VECT3L(x, y, z)   ((vect3l_t){(x), (y), (z)})
 
#define VECT2_EQ(a, b)   ((a).x == (b).x && (a).y == (b).y)
 
#define VECT3_EQ(a, b)    ((a).x == (b).x && (a).y == (b).y && (a).z == (b).z)
 
#define VECT2_PARALLEL(a, b)    (((a).y == 0 && (b).y == 0) || (((a).x / (a).y) == ((b).x / (b).y)))
 
#define ZERO_VECT2   ((vect2_t){0.0, 0.0})
 
#define ZERO_VECT3   ((vect3_t){0.0, 0.0, 0.0})
 
#define ZERO_VECT3L   ((vect3l_t){0.0, 0.0, 0.0})
 
#define NULL_VECT2   ((vect2_t){NAN, NAN})
 
#define NULL_VECT3   ((vect3_t){NAN, NAN, NAN})
 
#define NULL_VECT3L   ((vect3l_t){NAN, NAN, NAN})
 
#define NULL_GEO_POS3   ((geo_pos3_t){NAN, NAN, NAN})
 
#define NULL_GEO_POS3_32   ((geo_pos3_32_t){NAN, NAN, NAN})
 
#define NULL_GEO_POS2   ((geo_pos2_t){NAN, NAN})
 
#define NULL_GEO_POS2_32   ((geo_pos2_32_t){NAN, NAN})
 
#define IS_NULL_VECT(a)   (isnan((a).x))
 
#define IS_NULL_VECT2(a)   (isnan((a).x) || isnan((a).y))
 
#define IS_NULL_VECT3(a)   (isnan((a).x) || isnan((a).y) || isnan((a).z))
 
#define IS_FINITE_VECT2(a)   (isfinite((a).x) && isfinite((a).y))
 
#define IS_FINITE_VECT3(a)    (isfinite((a).x) && isfinite((a).y) && isfinite((a).z))
 
#define IS_NULL_GEO_POS(a)   (isnan((a).lat))
 
#define IS_NULL_GEO_POS2(a)    (isnan((a).lat) || isnan((a).lon))
 
#define IS_NULL_GEO_POS3(a)    (isnan((a).lat) || isnan((a).lon) || isnan((a).elev))
 
#define IS_ZERO_VECT2(a)   ((a).x == 0.0 && (a).y == 0.0)
 
#define IS_ZERO_VECT3(a)   ((a).x == 0.0 && (a).y == 0.0 && (a).z == 0.0)
 
#define VECT2_TO_VECT3(v, z)   ((vect3_t){(v).x, (v).y, (z)})
 
#define VECT3_TO_VECT2(v)   ((vect2_t){(v).x, (v).y})
 
#define VECT3L_TO_VECT3(v)   ((vect3_t){(v).x, (v).y, (v).z})
 
#define VECT3_TO_VECT3L(v)   ((vect3l_t){(v).x, (v).y, (v).z})
 
#define GEO2_TO_GEO3(v, a)   ((geo_pos3_t){(v).lat, (v).lon, (a)})
 
#define GEO3_TO_GEO2(v)   ((geo_pos2_t){(v).lat, (v).lon})
 
#define GEO3_FT2M(g)   GEO_POS3((g).lat, (g).lon, FEET2MET((g).elev))
 
#define GEO3_M2FT(g)   GEO_POS3((g).lat, (g).lon, MET2FEET((g).elev))
 
#define GEO3_EQ(p1, p2)
 
#define GEO2_EQ(p1, p2)   ((p1).lat == (p2).lat && (p1).lon == (p2).lon)
 
#define EARTH_MSL   6371200
 
#define PRINT_VECT2(v)   printf(#v "(%f, %f)\n", v.x, v.y)
 
#define PRINT_VECT3(v)   printf(#v "(%f, %f, %f)\n", v.x, v.y, v.z)
 
#define PRINT_VECT3L(v)   printf(#v "(%Lf, %Lf, %Lf)\n", v.x, v.y, v.z)
 
#define PRINT_GEO2(p)   printf(#p "(%f, %f)\n", p.lat, p.lon)
 
#define PRINT_GEO3(p)   printf(#p "(%f, %f, %f)\n", p.lat, p.lon, p.elev)
 
#define MAT4(mat, col, row)   ((mat)->_mat4_data[(col) * 4 + (row)])
 
#define MAT3(mat, col, row)   ((mat)->_mat3_data[(col) * 3 + (row)])
 
#define MAT4_DATA(mat)   ((mat)->_mat4_data)
 
#define MAT3_DATA(mat)   ((mat)->_mat3_data)
 

Functions

bool_t is_on_arc (double angle_x, double angle1, double angle2, bool_t cw)
 
double rel_angle (double a1, double a2)
 
double vect3_abs (vect3_t a)
 
long double vect3l_abs (vect3l_t a)
 
double vect3_dist (vect3_t a, vect3_t b)
 
long double vect3l_dist (vect3l_t a, vect3l_t b)
 
double vect2_abs (vect2_t a)
 
double vect2_dist (vect2_t a, vect2_t b)
 
vect3_t vect3_set_abs (vect3_t a, double abs)
 
vect3l_t vect3l_set_abs (vect3l_t a, long double abs)
 
vect2_t vect2_set_abs (vect2_t a, double abs)
 
vect3_t vect3_unit (vect3_t a, double *l)
 
vect2_t vect2_unit (vect2_t a, double *l)
 
vect3_t vect3_add (vect3_t a, vect3_t b)
 
vect3l_t vect3l_add (vect3l_t a, vect3l_t b)
 
vect2_t vect2_add (vect2_t a, vect2_t b)
 
vect3_t vect3_sub (vect3_t a, vect3_t b)
 
vect3l_t vect3l_sub (vect3l_t a, vect3l_t b)
 
vect2_t vect2_sub (vect2_t a, vect2_t b)
 
vect3_t vect3_mul (vect3_t a, vect3_t b)
 
vect3l_t vect3l_mul (vect3l_t a, vect3l_t b)
 
vect2_t vect2_mul (vect2_t a, vect2_t b)
 
vect3_t vect3_scmul (vect3_t a, double b)
 
vect3l_t vect3l_scmul (vect3l_t a, long double b)
 
vect2_t vect2_scmul (vect2_t a, double b)
 
double vect3_dotprod (vect3_t a, vect3_t b)
 
long double vect3l_dotprod (vect3l_t a, vect3l_t b)
 
double vect2_dotprod (vect2_t a, vect2_t b)
 
vect3_t vect3_xprod (vect3_t a, vect3_t b)
 
vect3l_t vect3l_xprod (vect3l_t a, vect3l_t b)
 
vect3_t vect3_mean (vect3_t a, vect3_t b)
 
vect3l_t vect3l_mean (vect3l_t a, vect3l_t b)
 
vect2_t vect2_mean (vect2_t a, vect2_t b)
 
vect2_t vect2_norm (vect2_t v, bool_t right)
 
vect3_t vect3_rot (vect3_t v, double angle, unsigned axis)
 
vect3l_t vect3l_rot (vect3l_t v, long double angle, unsigned axis)
 
vect2_t vect2_rot (vect2_t v, double angle)
 
vect2_t vect2_rot_inv_y (vect2_t v, double angle)
 
vect3_t vect3_neg (vect3_t v)
 
vect3l_t vect3l_neg (vect3l_t v)
 
vect2_t vect2_neg (vect2_t v)
 
vect3_t vect3_local2acf (vect3_t v, double roll, double pitch, double hdgt)
 
vect3_t vect3_acf2local (vect3_t v, double roll, double pitch, double hdgt)
 
ellip_t ellip_init (double semi_major, double semi_minor, double flattening)
 
geo_pos3_t geo2sph (geo_pos3_t pos, const ellip_t *ellip)
 
vect3_t geo2ecef_mtr (geo_pos3_t pos, const ellip_t *ellip)
 
vect3_t geo2ecef_ft (geo_pos3_t pos, const ellip_t *ellip)
 
geo_pos3_t ecef2geo (vect3_t pos, const ellip_t *ellip)
 
geo_pos3_t ecef2sph (vect3_t v)
 
vect3_t sph2ecef (geo_pos3_t pos)
 
vect3_t ecef2gl (vect3_t ecmi)
 
vect3_t gl2ecef (vect3_t opengl)
 
vect3l_t ecef2gl_l (vect3l_t ecmi)
 
vect3l_t gl2ecef_l (vect3l_t opengl)
 
vect3_t geo2ecmi (geo_pos3_t pos, double delta_t, const ellip_t *ellip)
 
geo_pos3_t ecmi2geo (vect3_t pos, double delta_t, const ellip_t *ellip)
 
vect3_t sph2ecmi (geo_pos3_t pos, double delta_t)
 
geo_pos3_t ecmi2sph (vect3_t pos, double delta_t)
 
vect3_t ecef2ecmi (vect3_t ecef, double delta_t)
 
vect3_t ecmi2ecef (vect3_t ecmi, double delta_t)
 
unsigned vect2sph_isect (vect3_t v, vect3_t o, vect3_t c, double r, bool_t confined, vect3_t i[2])
 
unsigned vect2circ_isect (vect2_t v, vect2_t o, vect2_t c, double r, bool_t confined, vect2_t i[2])
 
vect2_t vect2vect_isect (vect2_t da, vect2_t oa, vect2_t db, vect2_t ob, bool_t confined)
 
unsigned circ2circ_isect (vect2_t ca, double ra, vect2_t cb, double rb, vect2_t i[2])
 
unsigned vect2poly_isect_get (vect2_t a, vect2_t oa, const vect2_t *poly, vect2_t *isects, unsigned cap)
 
unsigned vect2poly_isect (vect2_t a, vect2_t oa, const vect2_t *poly)
 
bool_t point_in_poly (vect2_t pt, const vect2_t *poly)
 
vect2_t hdg2dir (double truehdg)
 
double dir2hdg (vect2_t dir)
 
geo_pos2_t geo_displace (const ellip_t *ellip, geo_pos2_t pos, double truehdg, double dist)
 
geo_pos2_t geo_displace_dir (const ellip_t *ellip, geo_pos2_t pos, vect2_t dir, double dist)
 
bool_t geo_pos2_from_str (const char *lat, const char *lon, geo_pos2_t *pos)
 
bool_t geo_pos3_from_str (const char *lat, const char *lon, const char *elev, geo_pos3_t *pos)
 
sph_xlate_t sph_xlate_init (geo_pos2_t displacement, double rotation, bool_t inv)
 
geo_pos2_t sph_xlate (geo_pos2_t pos, const sph_xlate_t *xlate)
 
vect3_t sph_xlate_vect (vect3_t pos, const sph_xlate_t *xlate)
 
double gc_distance (geo_pos2_t start, geo_pos2_t end)
 
double gc_point_hdg (geo_pos2_t start, geo_pos2_t end)
 
fpp_t fpp_init (geo_pos2_t center, double rot, double dist, const ellip_t *ellip, bool_t allow_inv)
 
fpp_t ortho_fpp_init (geo_pos2_t center, double rot, const ellip_t *ellip, bool_t allow_inv)
 
fpp_t gnomo_fpp_init (geo_pos2_t center, double rot, const ellip_t *ellip, bool_t allow_inv)
 
fpp_t stereo_fpp_init (geo_pos2_t center, double rot, const ellip_t *ellip, bool_t allow_inv)
 
vect2_t geo2fpp (geo_pos2_t pos, const fpp_t *fpp)
 
geo_pos2_t fpp2geo (vect2_t pos, const fpp_t *fpp)
 
void fpp_set_scale (fpp_t *fpp, vect2_t scale)
 
vect2_t fpp_get_scale (const fpp_t *fpp)
 
double fpp_get_gc_distance (vect2_t p1, vect2_t p2, const fpp_t *fpp)
 
lcc_t lcc_init (double reflat, double reflon, double stdpar1, double stdpar2)
 
vect2_t geo2lcc (geo_pos2_t pos, const lcc_t *lcc)
 
bezier_tbezier_alloc (size_t num_pts)
 
void bezier_free (bezier_t *curve)
 
double quad_bezier_func (double x, const bezier_t *func)
 
double * quad_bezier_func_inv (double y, const bezier_t *func, size_t *n_xs)
 
void mat4_ident (mat4_t *mat)
 
void mat3_ident (mat3_t *mat)
 

Variables

const ellip_t wgs84
 

Detailed Description

This file contains LOTS of utility functions and types to handle various geometric operations.

Definition in file geom.h.

Macro Definition Documentation

◆ DEG2RAD

#define DEG2RAD (   d)    ((d) * RAD2DEG_RATIO)

Converts degrees to radians.

Definition at line 156 of file geom.h.

◆ DEG2RAD_RATIO

#define DEG2RAD_RATIO   (180.0 / M_PI)

Internal. Use DEG2RAD() and RAD2DEG() instead.

Definition at line 154 of file geom.h.

◆ EARTH_MSL

#define EARTH_MSL   6371200

Mean radius Earth at sea level in meters.

Definition at line 285 of file geom.h.

◆ GEO2_EQ

#define GEO2_EQ (   p1,
  p2 
)    ((p1).lat == (p2).lat && (p1).lon == (p2).lon)
Returns
True if 2-space geographic coordinates p1 and p2 are equal.

Definition at line 282 of file geom.h.

◆ GEO2_TO_GEO3

#define GEO2_TO_GEO3 (   v,
 
)    ((geo_pos3_t){(v).lat, (v).lon, (a)})

Extends a 2-space geo_pos2_t v into a geo_pos3_t by appending the elevation coordinate a.

Definition at line 270 of file geom.h.

◆ GEO3_EQ

#define GEO3_EQ (   p1,
  p2 
)
Value:
((p1).lat == (p2).lat && (p1).lon == (p2).lon && \
(p1).elev == (p2).elev)
Returns
True if 3-space geographic coordinates p1 and p2 are equal.

Definition at line 278 of file geom.h.

◆ GEO3_FT2M

#define GEO3_FT2M (   g)    GEO_POS3((g).lat, (g).lon, FEET2MET((g).elev))

Converts a geo_pos3_t using feet for elevation into meters.

Definition at line 274 of file geom.h.

◆ GEO3_M2FT

#define GEO3_M2FT (   g)    GEO_POS3((g).lat, (g).lon, MET2FEET((g).elev))

Converts a geo_pos3_t using meters for elevation into feet.

Definition at line 276 of file geom.h.

◆ GEO3_TO_GEO2

#define GEO3_TO_GEO2 (   v)    ((geo_pos2_t){(v).lat, (v).lon})

Same as TO_GEO2().

Definition at line 272 of file geom.h.

◆ GEO_POS2

#define GEO_POS2 (   lat,
  lon 
)    ((geo_pos2_t){(lat), (lon)})
Returns
A geo_pos2_t with lat and lon.

Definition at line 164 of file geom.h.

◆ GEO_POS2_F32

#define GEO_POS2_F32 (   lat,
  lon 
)    ((geo_pos2_f32_t){(lat), (lon)})
Returns
A geo_pos2_32_t with lat and lon.

Definition at line 170 of file geom.h.

◆ GEO_POS3

#define GEO_POS3 (   lat,
  lon,
  elev 
)    ((geo_pos3_t){(lat), (lon), (elev)})
Returns
A geo_pos3_t with lat, lon and elev.

Definition at line 166 of file geom.h.

◆ GEO_POS3_F32

#define GEO_POS3_F32 (   lat,
  lon,
  elev 
)    ((geo_pos3_f32_t){(lat), (lon), (elev)})
Returns
A geo_pos3_32_t with lat, lon and elev.

Definition at line 168 of file geom.h.

◆ IS_FINITE_VECT2

#define IS_FINITE_VECT2 (   a)    (isfinite((a).x) && isfinite((a).y))
Returns
True if all coordinates of vector a are finite.

Definition at line 234 of file geom.h.

◆ IS_FINITE_VECT3

#define IS_FINITE_VECT3 (   a)     (isfinite((a).x) && isfinite((a).y) && isfinite((a).z))
Returns
True if all coordinates of vector a are finite.

Definition at line 236 of file geom.h.

◆ IS_NULL_GEO_POS

#define IS_NULL_GEO_POS (   a)    (isnan((a).lat))
Returns
True if the lat coordinate of a is NAN.

Definition at line 239 of file geom.h.

◆ IS_NULL_GEO_POS2

#define IS_NULL_GEO_POS2 (   a)     (isnan((a).lat) || isnan((a).lon))
Returns
True if any coordinate of a is NAN.

Definition at line 241 of file geom.h.

◆ IS_NULL_GEO_POS3

#define IS_NULL_GEO_POS3 (   a)     (isnan((a).lat) || isnan((a).lon) || isnan((a).elev))
Returns
True if any coordinate of a is NAN.

Definition at line 244 of file geom.h.

◆ IS_NULL_VECT

#define IS_NULL_VECT (   a)    (isnan((a).x))
Returns
True if the X coordinate of vector a is NAN.

Definition at line 228 of file geom.h.

◆ IS_NULL_VECT2

#define IS_NULL_VECT2 (   a)    (isnan((a).x) || isnan((a).y))
Returns
True if either the X or Y coordinate of vector a is NAN.

Definition at line 230 of file geom.h.

◆ IS_NULL_VECT3

#define IS_NULL_VECT3 (   a)    (isnan((a).x) || isnan((a).y) || isnan((a).z))
Returns
True if either the X, Y or Z coordinate of vector a is NAN.

Definition at line 232 of file geom.h.

◆ IS_ZERO_VECT2

#define IS_ZERO_VECT2 (   a)    ((a).x == 0.0 && (a).y == 0.0)
Returns
True if all coordinates of a are zero.

Definition at line 247 of file geom.h.

◆ IS_ZERO_VECT3

#define IS_ZERO_VECT3 (   a)    ((a).x == 0.0 && (a).y == 0.0 && (a).z == 0.0)
Returns
True if all coordinates of a are zero.

Definition at line 249 of file geom.h.

◆ MAT3

#define MAT3 (   mat,
  col,
  row 
)    ((mat)->_mat3_data[(col) * 3 + (row)])

Definition at line 533 of file geom.h.

◆ MAT3_DATA

#define MAT3_DATA (   mat)    ((mat)->_mat3_data)

Definition at line 535 of file geom.h.

◆ MAT4

#define MAT4 (   mat,
  col,
  row 
)    ((mat)->_mat4_data[(col) * 4 + (row)])

Definition at line 532 of file geom.h.

◆ MAT4_DATA

#define MAT4_DATA (   mat)    ((mat)->_mat4_data)

Definition at line 534 of file geom.h.

◆ NULL_GEO_POS2

#define NULL_GEO_POS2   ((geo_pos2_t){NAN, NAN})
Returns
A geo_pos2_t with all coordinates set to NAN.

Definition at line 224 of file geom.h.

◆ NULL_GEO_POS2_32

#define NULL_GEO_POS2_32   ((geo_pos2_32_t){NAN, NAN})
Returns
A geo_pos2_32_t with all coordinates set to NAN.

Definition at line 226 of file geom.h.

◆ NULL_GEO_POS3

#define NULL_GEO_POS3   ((geo_pos3_t){NAN, NAN, NAN})
Returns
A geo_pos3_t with all coordinates set to NAN.

Definition at line 220 of file geom.h.

◆ NULL_GEO_POS3_32

#define NULL_GEO_POS3_32   ((geo_pos3_32_t){NAN, NAN, NAN})
Returns
A geo_pos3_32_t with all coordinates set to NAN.

Definition at line 222 of file geom.h.

◆ NULL_VECT2

#define NULL_VECT2   ((vect2_t){NAN, NAN})
Returns
A vect2_t with all coordinates set to NAN.

Definition at line 214 of file geom.h.

◆ NULL_VECT3

#define NULL_VECT3   ((vect3_t){NAN, NAN, NAN})
Returns
A vect3_t with all coordinates set to NAN.

Definition at line 216 of file geom.h.

◆ NULL_VECT3L

#define NULL_VECT3L   ((vect3l_t){NAN, NAN, NAN})
Returns
A vect3l_t with all coordinates set to NAN.

Definition at line 218 of file geom.h.

◆ PRINT_GEO2

#define PRINT_GEO2 (   p)    printf(#p "(%f, %f)\n", p.lat, p.lon)

Definition at line 292 of file geom.h.

◆ PRINT_GEO3

#define PRINT_GEO3 (   p)    printf(#p "(%f, %f, %f)\n", p.lat, p.lon, p.elev)

Definition at line 293 of file geom.h.

◆ PRINT_VECT2

#define PRINT_VECT2 (   v)    printf(#v "(%f, %f)\n", v.x, v.y)

Definition at line 289 of file geom.h.

◆ PRINT_VECT3

#define PRINT_VECT3 (   v)    printf(#v "(%f, %f, %f)\n", v.x, v.y, v.z)

Definition at line 290 of file geom.h.

◆ PRINT_VECT3L

#define PRINT_VECT3L (   v)    printf(#v "(%Lf, %Lf, %Lf)\n", v.x, v.y, v.z)

Definition at line 291 of file geom.h.

◆ RAD2DEG

#define RAD2DEG (   r)    ((r) * DEG2RAD_RATIO)

Converts radians to degrees.

Definition at line 158 of file geom.h.

◆ RAD2DEG_RATIO

#define RAD2DEG_RATIO   (M_PI / 180.0)

Internal. Use DEG2RAD() and RAD2DEG() instead.

Definition at line 152 of file geom.h.

◆ TO_GEO2

#define TO_GEO2 (   geo2)     ((geo_pos2_t){(geo2).lat, (geo2).lon})

Converts any object in geo2 with the fields lat and lon into a geo_pos2_t.

Definition at line 181 of file geom.h.

◆ TO_GEO2_32

#define TO_GEO2_32 (   geo2)     ((geo_pos3_32_t){(geo3).lat, (geo3).lon})

Same as TO_GEO2() but returns a geo_pos2_32_t instead.

Definition at line 187 of file geom.h.

◆ TO_GEO3

#define TO_GEO3 (   geo3)     ((geo_pos3_t){(geo3).lat, (geo3).lon, (geo3).elev})

Converts any object in geo3 with the fields lat, lon and elev into a geo_pos3_t.

Definition at line 175 of file geom.h.

◆ TO_GEO3_32

#define TO_GEO3_32 (   geo3)     ((geo_pos3_32_t){(geo3).lat, (geo3).lon, (geo3).elev})

Same as TO_GEO3() but returns a geo_pos3_32_t instead.

Definition at line 184 of file geom.h.

◆ VECT2

#define VECT2 (   x,
 
)    ((vect2_t){(x), (y)})
Returns
A vect2_t with x and y coordinates.

Definition at line 190 of file geom.h.

◆ VECT2_EQ

#define VECT2_EQ (   a,
 
)    ((a).x == (b).x && (a).y == (b).y)
Returns
True if 2-space coordinates a and b are equal.

Definition at line 196 of file geom.h.

◆ VECT2_PARALLEL

#define VECT2_PARALLEL (   a,
 
)     (((a).y == 0 && (b).y == 0) || (((a).x / (a).y) == ((b).x / (b).y)))
Returns
True if 2-space coordinates a and b are parallel.

Definition at line 201 of file geom.h.

◆ VECT2_TO_VECT3

#define VECT2_TO_VECT3 (   v,
 
)    ((vect3_t){(v).x, (v).y, (z)})

Extends a 2-space vect2_t into a vect3_t by adding a Z coordinate.

Definition at line 253 of file geom.h.

◆ VECT3

#define VECT3 (   x,
  y,
 
)    ((vect3_t){(x), (y), (z)})
Returns
A vect3_t with x, y and z coordinates.

Definition at line 192 of file geom.h.

◆ VECT3_EQ

#define VECT3_EQ (   a,
 
)     ((a).x == (b).x && (a).y == (b).y && (a).z == (b).z)
Returns
True if 3-space coordinates a and b are equal.

Definition at line 198 of file geom.h.

◆ VECT3_TO_VECT2

#define VECT3_TO_VECT2 (   v)    ((vect2_t){(v).x, (v).y})

Cuts a 3-space vect3_t down into a vect2_t by stripping away the Z coordinate.

Definition at line 258 of file geom.h.

◆ VECT3_TO_VECT3L

#define VECT3_TO_VECT3L (   v)    ((vect3l_t){(v).x, (v).y, (v).z})

Converts a vect3_t into a vect3l_t by type-casting to long double.

Definition at line 265 of file geom.h.

◆ VECT3L

#define VECT3L (   x,
  y,
 
)    ((vect3l_t){(x), (y), (z)})
Returns
A vect3l_t with x, y and z coordinates.

Definition at line 194 of file geom.h.

◆ VECT3L_TO_VECT3

#define VECT3L_TO_VECT3 (   v)    ((vect3_t){(v).x, (v).y, (v).z})

Converts a vect3l_t into a vect3_t by type-casting to double.

Definition at line 260 of file geom.h.

◆ ZERO_VECT2

#define ZERO_VECT2   ((vect2_t){0.0, 0.0})
Returns
A vect2_t with all coordinates set to 0.

Definition at line 208 of file geom.h.

◆ ZERO_VECT3

#define ZERO_VECT3   ((vect3_t){0.0, 0.0, 0.0})
Returns
A vect3_t with all coordinates set to 0.

Definition at line 210 of file geom.h.

◆ ZERO_VECT3L

#define ZERO_VECT3L   ((vect3l_t){0.0, 0.0, 0.0})
Returns
A vect3l_t with all coordinates set to 0.

Definition at line 212 of file geom.h.

Function Documentation

◆ bezier_alloc()

bezier_t * bezier_alloc ( size_t  n_pts)

Allocates a new generic Bezier curve structure with n_pts points. The resulting object must be freed using bezier_free().

See also
quad_bezier_func()
quad_bezier_func_inv()

Definition at line 1939 of file geom.c.

◆ bezier_free()

void bezier_free ( bezier_t curve)

Frees a generic Bezier curve previous allocated with bezier_alloc().

Definition at line 1953 of file geom.c.

◆ circ2circ_isect()

unsigned circ2circ_isect ( vect2_t  ca,
double  ra,
vect2_t  cb,
double  rb,
vect2_t  i[2] 
)

Computes the intersection of two circles. The circles are centered at ‘ca’ and ‘cb’ and have radii ‘ra’ and ‘rb’ respectively. The ‘i’ argument must point to an array capable of holding at least two points, which will be filled with the intersection points. The function returns the number of intersections (and appropriate slots filled in ‘i’). Possible values are:

  • 0: the circles do not intersect.
  • 1: the circles touch in one point.
  • 2: the circles intersection at two points.
  • UINT_MAX: the circles are identical (‘i’ is NOT populated).

Definition at line 1220 of file geom.c.

◆ dir2hdg()

double dir2hdg ( vect2_t  dir)

Given a direction vector, returns the true heading that the vector is pointing. See hdg2dir() for a description of the returned heading value. This function is the inverse of hdg2dir().

Definition at line 1371 of file geom.c.

◆ ecef2ecmi()

vect3_t ecef2ecmi ( vect3_t  pos,
double  delta_t 
)

Converts a series of Euclidian ECEF coordinates into ECmI coordinates at specified delta-time delta_t.

Definition at line 749 of file geom.c.

◆ ecef2geo()

geo_pos3_t ecef2geo ( vect3_t  pos,
const ellip_t ellip 
)

Does the reverse transform of geo2ecef_mtr(), by translating ECEF coordinates into geographic coordinates on an ellipsoid.

Parameters
posInput ECEF coordinates to be translated.
ellipDefinition of the ellipsoid to which pos is to be translated.
Returns
Geographic coordinates on ellipsoid ellip matching the position of ECEF coordinates pos. Elevation is encoded as meters.
See also
https://en.wikipedia.org/wiki/Earth-centered,_Earth-fixed_coordinate_system

Definition at line 900 of file geom.c.

◆ ecef2gl()

vect3_t ecef2gl ( vect3_t  ecef)

Converts ECEF coordinates into OpenGL (right-handed) coordinates.

Definition at line 772 of file geom.c.

◆ ecef2gl_l()

vect3l_t ecef2gl_l ( vect3l_t  ecef)

Same as ecef2gl(), but utilizing extended preicision coordinates.

Definition at line 790 of file geom.c.

◆ ecef2sph()

geo_pos3_t ecef2sph ( vect3_t  v)

Converts a 3-space coordinate vector from ECEF coordinate space into geocentric coordinates on an EARTH_MSL-radius sphere. This basically the same as ecef2geo(), but rather than using an ellipsoid, assumes the coordinates were specified on a perfect sphere.

Definition at line 987 of file geom.c.

◆ ecmi2ecef()

vect3_t ecmi2ecef ( vect3_t  pos,
double  delta_t 
)

Converts a series of Euclidian ECmI coordinates into ECEF coordinates at specified delta-time delta_t.

Definition at line 761 of file geom.c.

◆ ecmi2geo()

geo_pos3_t ecmi2geo ( vect3_t  pos,
double  delta_t,
const ellip_t ellip 
)

Converts ECmI coordinates into geographic coordinates.

Parameters
posInput ECmI coordinates.
delta_tDelta-time (in seconds) from the ECmI reference time.
ellipEarth ellipsoid to use. You'll probably want &wgs84 in here.
Returns
Geographic coordinates corresponding to the specified ECmI coordinates at reference time + delta_t.

Definition at line 712 of file geom.c.

◆ ecmi2sph()

geo_pos3_t ecmi2sph ( vect3_t  pos,
double  delta_t 
)

Similar to ecmi2geo(), but instead of using a WGS-84 ellipsoid, assumes that the Earth is perfectly spherical.

Definition at line 737 of file geom.c.

◆ ellip_init()

ellip_t ellip_init ( double  semi_major,
double  semi_minor,
double  flattening 
)

Initializes a new ellipsoid for use with functions which take a ellip_t argument. For the vast majority of use cases, you will NOT want to call this and instead use the pre-existing wgs84 ellipsoid.

Definition at line 811 of file geom.c.

◆ fpp2geo()

geo_pos2_t fpp2geo ( vect2_t  pos,
const fpp_t fpp 
)

Back-projects a point from a projection surface into spherical coordinate space. N.B. since projection loses some information about the original input point, back-projection is incomplete for projections where either:

  • the projection origin was non-negative, or
  • the projection origin was less than -EARTH_MSL

This means back-projection is only uniquely possible possible for gnomonic, stereographic and other projections where the projection origin lies "inside" the projected sphere. In case back-projection is not unique, the point closer to the projection origin is returned.

Definition at line 1787 of file geom.c.

◆ fpp_get_gc_distance()

double fpp_get_gc_distance ( vect2_t  p1,
vect2_t  p2,
const fpp_t fpp 
)
Returns
The great-circle distance between two projection points. The projection must have been created with the allow_inv argument set to true.

Definition at line 1875 of file geom.c.

◆ fpp_get_scale()

vect2_t fpp_get_scale ( const fpp_t fpp)
Returns
The scaling previously set using fpp_set_scale(). If no scaling is set, the default is VECT2(1, 1).

Definition at line 1863 of file geom.c.

◆ fpp_init()

fpp_t fpp_init ( geo_pos2_t  center,
double  rot,
double  dist,
const ellip_t ellip,
bool_t  allow_inv 
)

Prepares a set of projection parameters for projections from a fixed origin along the projection axis onto a flat projection plane. The plane is centered at ‘center’ and is rotated ‘rot’ degrees relative to the sphere's native coordinate system. The projection plane touches the sphere at the center point and is parallel to its surface there. Points on the sphere are projected from a fixed origin along a projection axis that is perpendicular to the projection plane and passes through its center. The distance of this point along the projection axis from the projection plane is ‘dist’ with positive offsets increasing away from the sphere's center.

projection.
center \ | <- projection axis (positive offsets)
v|
==============+=============+======= <- projection plane
- ' | ' - / ^-- projected point
/ | \ x <-- projecting point
/ | /\
| sphere | / |
| center -> + / |
| | / |
\ | / /
\ + <- projection origin
- | -
'----|----'
|
| <- projection axis (negative offsets)

You can pass INFINITY for ‘dist’, in which case the projection origin will be centered at +INFINITY, constructing an orthographic projection. N.B. ATM there is no way to position the projection point at -INFINITY. If you wish to construct an inverted orthographic projection, simply flip the ‘x’ coordinate of the projected points. Also, it is illegal to pass dist == 0.0.

Definition at line 1680 of file geom.c.

◆ fpp_set_scale()

void fpp_set_scale ( fpp_t fpp,
vect2_t  scale 
)

Sets a final output scaling vector for a flat plane projection previously created using one of the *fpp_init functions. This scaling vector is used to simply multiply the X and Y coordinates of the project's output. In essence, it is no different than doing:

vect2_mul(geo2fpp(pos, fpp), scale);
vect2_t geo2fpp(geo_pos2_t pos, const fpp_t *fpp)
Definition geom.c:1749
vect2_t vect2_mul(vect2_t a, vect2_t b)
Definition geom.c:181
See also
fpp_init()

Definition at line 1850 of file geom.c.

◆ gc_distance()

double gc_distance ( geo_pos2_t  start,
geo_pos2_t  end 
)
Returns
the great circle distance between two geodesic coordinates on the Earth in meters. This is using the WGS-84 ellipsoid.

Definition at line 1615 of file geom.c.

◆ gc_point_hdg()

double gc_point_hdg ( geo_pos2_t  start,
geo_pos2_t  end 
)

Computes the great-circle point heading from start to end. The heading is calculated at the position of the first argument. In essence, it asks the question "what heading to I need to be facing at `start` to move towards `end` along a great circle path." The underlying projection assumes a WGS-84 ellipsoid.

Definition at line 1637 of file geom.c.

◆ geo2ecef_ft()

vect3_t geo2ecef_ft ( geo_pos3_t  pos,
const ellip_t ellip 
)

Same as geo2ecef_mtr(), but the elevation component of pos is assumed to be in feet.

Definition at line 884 of file geom.c.

◆ geo2ecef_mtr()

vect3_t geo2ecef_mtr ( geo_pos3_t  pos,
const ellip_t ellip 
)

Converts a series of geographic coordinates on an ellipsoid into Euclidian coordinates in the ECEF coordinate system.

Parameters
posGeographic coordinates on the ellipsoid described in ellip. The elevation component of the coordinates is assumed to be in meters.
ellipDefinition of the ellipsoid on which pos exists.
Returns
A 3-space vector, corresponding to the position of pos in the ECEF coordinate system.
See also
https://en.wikipedia.org/wiki/Earth-centered,_Earth-fixed_coordinate_system

Definition at line 861 of file geom.c.

◆ geo2ecmi()

vect3_t geo2ecmi ( geo_pos3_t  pos,
double  delta_t,
const ellip_t ellip 
)

Converts geographic coordinates into ECmI coordinates.

Parameters
posInput geographic coordinates.
delta_tDelta-time (in seconds) from the ECmI reference time.
ellipEarth ellipsoid to use. You'll probably want &wgs84 in here.
Returns
ECmI coordinates corresponding to the specified geographic coordinates at reference time + delta_t.

Definition at line 695 of file geom.c.

◆ geo2fpp()

vect2_t geo2fpp ( geo_pos2_t  pos,
const fpp_t fpp 
)

Projects a point at ‘pos’ according to the projection ‘proj’ and returns a 2D vector to the projected point's location on the projection plane. If the specified point cannot be projected (because its projection falls outside of the projection plane), NULL_VECT2 is returned instead.

Definition at line 1749 of file geom.c.

◆ geo2lcc()

vect2_t geo2lcc ( geo_pos2_t  pos,
const lcc_t lcc 
)

Projects a point at ‘pos’ using the projection ‘lcc’.

Definition at line 1918 of file geom.c.

◆ geo2sph()

geo_pos3_t geo2sph ( geo_pos3_t  pos,
const ellip_t ellip 
)

Converts between geographic coordinates on an ellipsoid into equivalent geographic coordinates on a perfect sphere.

Parameters
posGeographic coordinates on the ellipsoid described in ellip.
ellipDefinition of the ellipsoid on which pos exists.
Returns
Coordinates pos expressed on a perfect sphere, as-if it was co-located with the ellipsoid.

Definition at line 831 of file geom.c.

◆ geo_displace()

geo_pos2_t geo_displace ( const ellip_t ellip,
geo_pos2_t  pos,
double  truehdg,
double  dist 
)

Given a starting coordinate and displacement direction + distance, displaces the starting coordinates in the desired direction and distance along a great circle.

Parameters
ellipAn optional ellipsoid pointer, describing the Earth ellipsoid to use. If NULL, then the projection uses a spherical Earth model.
posThe starting position of the displacement.
truehdgThe direction of the displacement in degrees from true north.
distThe distance of the displacement in meters.
Returns
The displaced coordinates along a great circle, in the direction of truehdg and for dist meters.

Definition at line 1405 of file geom.c.

◆ geo_displace_dir()

geo_pos2_t geo_displace_dir ( const ellip_t ellip,
geo_pos2_t  pos,
vect2_t  dir,
double  dist 
)

Same as geo_displace(), but uses a unit direction vector instead of a heading in degrees. This is equivalent to just converting the heading into a direction vector first, using hdg2dir().

See also
geo_displace()

Definition at line 1417 of file geom.c.

◆ geo_pos2_from_str()

bool_t geo_pos2_from_str ( const char *  lat,
const char *  lon,
geo_pos2_t pos 
)

Parses a series of strings for latitude and longitude and uses them to construct a geo_pos2_t, with checking for correctness.

Parameters
latThe latitude in fractional degrees (positive north).
lonThe longitude in fractional degrees (positive east).
posA mandatory return argument that will be filled the resulting geographic coordinates.
Returns
B_TRUE if the input coordinates were a valid latitude & longitude. If the input contained invalid data, returns B_FALSE instead and you shouldn't use the returned pos.

Definition at line 1442 of file geom.c.

◆ geo_pos3_from_str()

bool_t geo_pos3_from_str ( const char *  lat,
const char *  lon,
const char *  elev,
geo_pos3_t pos 
)

Same as geo_pos2_from_str(), but includes an elevation argument and returns a geo_pos3_t.

Definition at line 1454 of file geom.c.

◆ gl2ecef()

vect3_t gl2ecef ( vect3_t  opengl)

Converts OpenGL (right-handed) coordinates into ECEF coordinates.

Definition at line 781 of file geom.c.

◆ gl2ecef_l()

vect3l_t gl2ecef_l ( vect3l_t  opengl)

Same as gl2ecef(), but utilizing extended preicision coordinates.

Definition at line 799 of file geom.c.

◆ gnomo_fpp_init()

fpp_t gnomo_fpp_init ( geo_pos2_t  center,
double  rot,
const ellip_t ellip,
bool_t  allow_inv 
)

Constructs a gnomonic projection. This is a flat plane projection with the origin at the Earth's center.

See also
fpp_init()

Definition at line 1723 of file geom.c.

◆ hdg2dir()

vect2_t hdg2dir ( double  truehdg)

Given a true heading in degrees, constructs a unit vector pointing in that direction. 0 degress is parallel with y axis and hdg increases clockwise.

Definition at line 1359 of file geom.c.

◆ is_on_arc()

bool_t is_on_arc ( double  angle_x,
double  angle1,
double  angle2,
bool_t  cw 
)

Determines whether an angle is part of an arc.

Parameters
angle_xAngle who's membership of the arc to examine (in degrees).
angle1Start angle of the arc (in degrees).
angle2End angle of the arc (in degrees).
cwFlag indicating whether the arc progresses clockwise or counter clockwise from angle1 to angle2.
Returns
B_TRUE if angle_x is on the arc, B_FALSE if it is not.

Definition at line 93 of file geom.c.

◆ lcc_init()

lcc_t lcc_init ( double  reflat,
double  reflon,
double  stdpar1,
double  stdpar2 
)

Prepares a set of Lambert conformal conic projection parameters.

Parameters
reflatReference latitude in degrees.
reflonReference longitude in degrees.
stdpar1First standard parallel in degrees.
stdpar2Second standard parallel in degrees.
Returns
The set of lcc parameters to pass to geo2lcc.

Definition at line 1892 of file geom.c.

◆ mat3_ident()

void mat3_ident ( mat3_t mat)

Constructs a 3x3 identity matrix in mat.

Definition at line 2145 of file geom.c.

◆ mat4_ident()

void mat4_ident ( mat4_t mat)

Constructs a 4x4 identity matrix in mat.

Definition at line 2132 of file geom.c.

◆ ortho_fpp_init()

fpp_t ortho_fpp_init ( geo_pos2_t  center,
double  rot,
const ellip_t ellip,
bool_t  allow_inv 
)

Constructs an orthographic projection. This is a flat plane projection with the projection origin at +INFINITY.

See also
fpp_init()

Definition at line 1711 of file geom.c.

◆ point_in_poly()

bool_t point_in_poly ( vect2_t  pt,
const vect2_t poly 
)

Checks if a point lies inside of a polygon.

Parameters
ptA vector pointing to the position of the point to examine.
polyAn array of 2-space vectors specifying the points of the polygon. Must contain at least 3 points and must be terminated by a final NULL_VECT2 point.
Returns
B_TRUE if the point lies inside of poly, B_FALSE otherwise.

Definition at line 1340 of file geom.c.

◆ quad_bezier_func()

double quad_bezier_func ( double  x,
const bezier_t func 
)

Calculates the value of a function defined by a set of quadratic bezier curve segments.

Parameters
xFunction input value.
funcThe set of quadratic bezier curves defining the function. Please note that since this is a function, curve segments may not overlap. This is to guarantee that at any point x the function resolves to one value.
Returns
The function value at point x. If the point is beyond the edges of the bezier curve segments describing the function, the y value of the first or last curve point is returned, i.e. beyond the curve boundaries, the function is assumed to be flat.

Definition at line 1975 of file geom.c.

◆ quad_bezier_func_inv()

double * quad_bezier_func_inv ( double  y,
const bezier_t func,
size_t *  n_xs 
)

Calculates the value of a function ‘g’ defined as the inverse of a function ‘f’ which is defined by a set of quadratic bezier curve segments:

g(f(x)) = x

IOW, this function is the inverse of quad_bezier_func(), i.e. it looks for an unknown ‘x’ input to quad_bezier_func() that produces a known ‘y’ output. Please note that the ‘func’ argument of quad_bezier_func need not be a bijective function definition, so quad_bezier_func_inv() can return multiple ‘x’ values that all map to the given ‘y’ value. As a special case, if the ‘func’ definition includes a constant portion (i.e. a potentially infinite number of ‘x’ values corresponds to a given ‘y’ value), quad_bezier_func_inv() returns NULL and sets n_xs to SIZE_MAX. You should treat this case as "infinite solutions."

Parameters
yOutput value of the function func for which to look for a suitable ‘x’ input value.
funcThe set of quadratic bezier curve defining the function with the same constraints as in quad_bezier_func.
n_xsOutput parameter which will be filled with the number of ‘x’ input points returned.
Returns
An array of ‘x’ values corresponding to the ‘y’ argument. The number of elements in this array is filled in ‘n_xs’. Caller is responsible for freeing this array using lacf_free().

Definition at line 2088 of file geom.c.

◆ rel_angle()

double rel_angle ( double  a1,
double  a2 
)

Expresses the relative angle needed to turn from a1 to a2, both specified in degrees and result is returned in degrees as well. This function handles angle wrapping and will always return a value in the range <-180,+180>.

Definition at line 623 of file geom.c.

◆ sph2ecef()

vect3_t sph2ecef ( geo_pos3_t  pos)

Converts surface coordinates on an Earth-sized sphere into 3-space coordinate vector in ECEF space. Please note that this considers the Earth to be a perfect sphere and hence cannot be used for very precise calculations. For more accurate conversions, use geo2ecef_mtr().

Parameters
posThe input position to convert.

In 3-space, axes have their origins at the globe center point, are perpendicular to each other and are designated as follows:

  • x: positive & passing through lat=0, lon=0
  • y: positive & passing through lat=0, lon=+90
  • z: positive & passing through lat=90
See also
geo2ecef_mtr()

Definition at line 663 of file geom.c.

◆ sph2ecmi()

vect3_t sph2ecmi ( geo_pos3_t  pos,
double  delta_t 
)

Similar to geo2ecmi(), but instead of using a WGS-84 ellipsoid, assumes that the Earth is perfectly spherical.

Definition at line 725 of file geom.c.

◆ sph_xlate()

geo_pos2_t sph_xlate ( geo_pos2_t  pos,
const sph_xlate_t xlate 
)

Translates a point at pos using the geo translation specified by xlate. Note that is assumes the planet to be a perfect sphere, rather than an ellipsoid.

Definition at line 1602 of file geom.c.

◆ sph_xlate_init()

sph_xlate_t sph_xlate_init ( geo_pos2_t  displac,
double  rot,
bool_t  inv 
)

Prepares a set of geographical coordinate translation parameters.

Parameters
displacThe relative latitude & longitude (in degrees) between the origins of the two respective coordinate systems. For example, a displacement of +10 degrees of latitude (north) and +20 degrees of longitude (east) will result in an input coordinate of +5,+5 translating into -5,-15 in the target system (assuming ‘rotation’ below is zero). Please note that these coordinates as well as all transformations are assumed to be in geocentric coordinates on the an EARTH_MSL radius spheroid.
rotThe relative rotation of the axes of the target coordinate system to the source coordinate system in degrees counter-clockwise. For example, a rotation of +90 degrees and no translation applied to an input coordinate of +5 degrees of latitude (north) and +5 degrees of longitude (east) will translate into -5,+5.

Definition at line 1498 of file geom.c.

◆ sph_xlate_vect()

vect3_t sph_xlate_vect ( vect3_t  p,
const sph_xlate_t xlate 
)

Translates a point at ECEF coordinates pos using the spherical translation specified by xlate. Note that is assumes the planet to be a perfect sphere, rather than an ellipsoid.

Definition at line 1565 of file geom.c.

◆ stereo_fpp_init()

fpp_t stereo_fpp_init ( geo_pos2_t  center,
double  rot,
const ellip_t ellip,
bool_t  allow_inv 
)

Constructs a stereographic projection. This is a projection with the origin at the intersection of the projection axis and the surface of the Earth opposite the projection plane's center point.

See also
fpp_init()

Definition at line 1736 of file geom.c.

◆ vect2_abs()

double vect2_abs ( vect2_t  a)

Same as vect3_abs(), but for 2-space vectors.

Definition at line 151 of file geom.c.

◆ vect2_add()

vect2_t vect2_add ( vect2_t  a,
vect2_t  b 
)

Same as vect3_add(), but for 2-space vectors.

Definition at line 310 of file geom.c.

◆ vect2_dist()

double vect2_dist ( vect2_t  a,
vect2_t  b 
)

Same as vect3_dist(), but for 2-space vectors.

Definition at line 190 of file geom.c.

◆ vect2_dotprod()

double vect2_dotprod ( vect2_t  a,
vect2_t  b 
)

Same as vect3_dotprod(), but for 2-space vectors.

Definition at line 404 of file geom.c.

◆ vect2_mean()

vect2_t vect2_mean ( vect2_t  a,
vect2_t  b 
)

Same as vect3_mean() but for 2-space vectors.

Definition at line 466 of file geom.c.

◆ vect2_mul()

vect2_t vect2_mul ( vect2_t  a,
vect2_t  b 
)

Same as vect3_mul(), but for 2-space vectors.

Definition at line 181 of file geom.c.

◆ vect2_neg()

vect2_t vect2_neg ( vect2_t  v)

Same as vect3_neg() but for 2-space vectors.

Definition at line 587 of file geom.c.

◆ vect2_norm()

vect2_t vect2_norm ( vect2_t  v,
bool_t  right 
)

Rotates vector v by 90 degrees either to the right or left. This is faster than doing full trigonometric calculations in vect2_rot().

Definition at line 536 of file geom.c.

◆ vect2_rot()

vect2_t vect2_rot ( vect2_t  v,
double  a 
)

Rotates vector v by a degrees to the right.

Definition at line 548 of file geom.c.

◆ vect2_rot_inv_y()

vect2_t vect2_rot_inv_y ( vect2_t  v,
double  a 
)

Same as vect2_rot(), but assumes an inverted Y coordinate. This is used in X-Plane OpenGL coordinates, where the Y coordinate points south, not north.

Definition at line 559 of file geom.c.

◆ vect2_scmul()

vect2_t vect2_scmul ( vect2_t  a,
double  b 
)

Same as vect3_scmul(), but for 2-space vectors.

Definition at line 373 of file geom.c.

◆ vect2_set_abs()

vect2_t vect2_set_abs ( vect2_t  a,
double  abs 
)

Same as vect3_set_abs(), but for 2-space vectors.

Definition at line 227 of file geom.c.

◆ vect2_sub()

vect2_t vect2_sub ( vect2_t  a,
vect2_t  b 
)

Same as vect3_sub(), but for 2-space vectors.

Definition at line 341 of file geom.c.

◆ vect2_unit()

vect2_t vect2_unit ( vect2_t  a,
double *  l 
)

Same as vect3_unit(), but for 2-space vectors.

Definition at line 272 of file geom.c.

◆ vect2circ_isect()

unsigned vect2circ_isect ( vect2_t  v,
vect2_t  o,
vect2_t  c,
double  r,
bool_t  confined,
vect2_t  i[2] 
)

Determines whether and where a 2D vector intersects a 2D circle. The meanings of the arguments and return value are exactly the same as in vect2sph_isect().

Definition at line 1131 of file geom.c.

◆ vect2poly_isect()

unsigned vect2poly_isect ( vect2_t  a,
vect2_t  oa,
const vect2_t poly 
)

Same as vect2poly_isect_get(), but only returns the number of intersections. This function is primarily for legacy code that might depend on it. Use vect2poly_isect_get() for new code, as it provides more flexibility.

See also
vect2poly_isect_get()

Definition at line 1326 of file geom.c.

◆ vect2poly_isect_get()

unsigned vect2poly_isect_get ( vect2_t  a,
vect2_t  oa,
const vect2_t poly,
vect2_t isects,
unsigned  cap 
)

Checks if a vector and a polygon intersect.

Parameters
aDirection & magnitude of first vector.
oaVector pointing to the origin of the first vector.
polyAn array of 2-space vectors specifying the points of the polygon. Must contain at least 3 points and must be terminated by a final NULL_VECT2 point.
isectsAn optional return array that will be populated with the intersection points. At most ‘cap’ elements will be written to the array. The return value is the total number of intersections. Can be NULL if you do not wish to receive the intersections.
capNumber of elements in ‘isects’ that can be populated with intersections. No more than ‘cap’ elements will be written to isects.
Returns
The number of the polygon's sides that the vector intersects. Please note that this only checks intersection with the sides, not if the vector is contained completely inside the polygon. Use point_in_poly() with the vector's origin to test for that scenario.

Definition at line 1291 of file geom.c.

◆ vect2sph_isect()

unsigned vect2sph_isect ( vect3_t  v,
vect3_t  o,
vect3_t  c,
double  r,
bool_t  confined,
vect3_t  i[2] 
)

Determines whether and where a vector intersects the surface of a sphere. Returns the number of intersection points (zero, one or two).

Parameters
vVector for which to determine the intersection.
oVector pointing from the coordinate origin to the origin of vector v (i.e. displacement of ‘v’ from the origin).
cDisplacement of sphere center point from the coordinate origin.
rRadius of sphere.
confinedIf B_TRUE, only intersects which lie between the vector's start & ending point (inclusive) are returned. Otherwise any intersect along an infinite linear extension of the vector is returned.
iIf not NULL, this function stores vectors pointing to the intersection points from the coordinate origin in this array:
  • if 0 is returned, two null vectors are stored in the array.
  • if 1 is returned, one null vector and one non-null vector pointing to the intersection point are stored in the array (ordering in the array is not guarantted as described here).
  • if 2 is returned, two non-null vectors pointing to the intersection points are stored in the array.

Definition at line 1035 of file geom.c.

◆ vect2vect_isect()

vect2_t vect2vect_isect ( vect2_t  a,
vect2_t  oa,
vect2_t  b,
vect2_t  ob,
bool_t  confined 
)

Calculates a 2D vector-to-vector intersection point and returns it.

Parameters
aFirst vector.
oaVector to origin of first vector from the coordinate origin.
bSecond vector.
oaVector to origin of second vector from the coordinate origin.
confinedIf B_TRUE, only intersects which lie between the vectors' start & ending points (inclusive) are considered. Otherwise any intersect along an infinite linear extension of the vectors is returned.
Returns
A vector from the coordinate origin to the intersection point or NULL_VECT2 if the vectors are parallel (no intersection or inf many intersections if they're directly on top of each other).

Definition at line 1171 of file geom.c.

◆ vect3_abs()

double vect3_abs ( vect3_t  a)

Returns the absolute value (length) of a 3-space vector:

r = |a|

Definition at line 115 of file geom.c.

◆ vect3_acf2local()

vect3_t vect3_acf2local ( vect3_t  v,
double  roll,
double  pitch,
double  hdgt 
)

The inverse of vect3_local2acf().

Definition at line 610 of file geom.c.

◆ vect3_add()

vect3_t vect3_add ( vect3_t  a,
vect3_t  b 
)

Adds 3-space vectors a and b and returns the result:

_ _ _
r = a + b
#define _(str)
Definition intl.h:61

Definition at line 292 of file geom.c.

◆ vect3_dist()

double vect3_dist ( vect3_t  a,
vect3_t  b 
)
Returns
The distance between two points defined by vectors a and b.

Definition at line 133 of file geom.c.

◆ vect3_dotprod()

double vect3_dotprod ( vect3_t  a,
vect3_t  b 
)

Returns the dot product of 3-space vectors a and b:

_ _
r = a . b

Definition at line 386 of file geom.c.

◆ vect3_local2acf()

vect3_t vect3_local2acf ( vect3_t  v,
double  roll,
double  pitch,
double  hdgt 
)

Converts a vector from X-Plane local OpenGL coordinates to aircraft coordinates, given aircraft local roll, pitch and heading. This can also be used to convert from aircraft coordinates to the true reference frame, by using true_phi, true_theta and true_psi intead of their local equivalents.

Definition at line 600 of file geom.c.

◆ vect3_mean()

vect3_t vect3_mean ( vect3_t  a,
vect3_t  b 
)

Returns the mean vector of 3-space vectors a and b. That is, the resulting vector will point exactly in between a and b:

^.
| .
| .
a | x.
| / c .
| / .
+----------->
b

Definition at line 448 of file geom.c.

◆ vect3_mul()

vect3_t vect3_mul ( vect3_t  a,
vect3_t  b 
)

Performs a simple per-component multiplication of two vectors.

x = VECT3(a.x * b.x, a.y * b.y, a.z * b.z);
#define VECT3(x, y, z)
Definition geom.h:192

Definition at line 163 of file geom.c.

◆ vect3_neg()

vect3_t vect3_neg ( vect3_t  v)
Returns
The negation of vector v, so it point in the opposite direction.

Definition at line 569 of file geom.c.

◆ vect3_rot()

vect3_t vect3_rot ( vect3_t  v,
double  a,
unsigned  axis 
)

Rotates vector vby a degrees around a given axis. The axis argument selects which axis to rotate around (clockwise):

  • axis = 0: rotate around the x axis.
  • axis = 1: rotate around the y axis.
  • axis = 2: rotate around the z axis.

Definition at line 479 of file geom.c.

◆ vect3_scmul()

vect3_t vect3_scmul ( vect3_t  a,
double  b 
)

Performs a scalar multiply of 3-space vector a and scalar value b and returns the result:

r = ab

Definition at line 355 of file geom.c.

◆ vect3_set_abs()

vect3_t vect3_set_abs ( vect3_t  a,
double  abs 
)

Sets the absolute value (length) of a vector without changing its orientation. If the input vector has zero length, this returns ZERO_VECT3.

Definition at line 201 of file geom.c.

◆ vect3_sub()

vect3_t vect3_sub ( vect3_t  a,
vect3_t  b 
)

Subtracts 3-space vector b from vector a and returns the result:

_ _ _
r = a - b

Definition at line 323 of file geom.c.

◆ vect3_unit()

vect3_t vect3_unit ( vect3_t  a,
double *  l 
)
Returns
A unit vector (vector with identical orientation but a length of 1) for a given input vector. If the optional argument l is not NULL, the length of the input vector is stored in it.

Definition at line 242 of file geom.c.

◆ vect3_xprod()

vect3_t vect3_xprod ( vect3_t  a,
vect3_t  b 
)

Returns the cross product of 3-space vectors a and b:

_ _ _
r = a x b

Definition at line 417 of file geom.c.

◆ vect3l_abs()

long double vect3l_abs ( vect3l_t  a)

Same as vect3_abs(), but for long-double vectors.

Definition at line 124 of file geom.c.

◆ vect3l_add()

vect3l_t vect3l_add ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_add(), but for long-double vectors.

Definition at line 301 of file geom.c.

◆ vect3l_dist()

long double vect3l_dist ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_dist(), but for long-double vectors.

Definition at line 142 of file geom.c.

◆ vect3l_dotprod()

long double vect3l_dotprod ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_dotprod(), but for long-double vectors.

Definition at line 395 of file geom.c.

◆ vect3l_mean()

vect3l_t vect3l_mean ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_mean(), but for long-double vectors.

Definition at line 457 of file geom.c.

◆ vect3l_mul()

vect3l_t vect3l_mul ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_mul(), but for long-double vectors.

Definition at line 172 of file geom.c.

◆ vect3l_neg()

vect3l_t vect3l_neg ( vect3l_t  v)

Same as vect3_neg(), but for long-double vectors.

Definition at line 578 of file geom.c.

◆ vect3l_rot()

vect3l_t vect3l_rot ( vect3l_t  v,
long double  a,
unsigned  axis 
)

Same as vect3_rot(), but for long-double vectors.

Definition at line 507 of file geom.c.

◆ vect3l_scmul()

vect3l_t vect3l_scmul ( vect3l_t  a,
long double  b 
)

Same as vect3_scmul(), but for long-double vectors.

Definition at line 364 of file geom.c.

◆ vect3l_set_abs()

vect3l_t vect3l_set_abs ( vect3l_t  a,
long double  abs 
)

Same as vect3_set_abs(), but for long-double vectors.

Definition at line 214 of file geom.c.

◆ vect3l_sub()

vect3l_t vect3l_sub ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_sub(), but for long-double vectors.

Definition at line 332 of file geom.c.

◆ vect3l_xprod()

vect3l_t vect3l_xprod ( vect3l_t  a,
vect3l_t  b 
)

Same as vect3_xprod(), but for long-double vectors.

Definition at line 427 of file geom.c.

Variable Documentation

◆ wgs84

const ellip_t wgs84
extern

The WGS-84 ellipsoid parameters. For most functions where you can pass a ellip_t, you will want to pass a pointer to this structure to use the WGS-84 ellipsoid.

Definition at line 38 of file geom.c.