YAC 3.7.1
Yet Another Coupler
Loading...
Searching...
No Matches
geometry.h File Reference
#include "config.h"
#include <math.h>
#include <float.h>
#include "basic_grid.h"
#include "grid_cell.h"
#include "utils_core.h"
Include dependency graph for geometry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sin_cos_angle
 
struct  bounding_circle
 
struct  yac_circle
 

Macros

#define YAC_RAD   (0.01745329251994329576923690768489)
 
#define yac_angle_tol   (1e-9)
 
#define yac_sq_angle_tol   (1e-9 * 1e-9)
 
#define yac_cos_angle_tol   (0.9999999999999999995)
 
#define yac_angle_low_tol   (1e-11)
 
#define yac_cos_angle_low_tol   (1.0)
 

Enumerations

enum  yac_circle_type { GREAT_CIRCLE = YAC_GREAT_CIRCLE_EDGE , LAT_CIRCLE = YAC_LAT_CIRCLE_EDGE , LON_CIRCLE = YAC_LON_CIRCLE_EDGE , POINT }
 

Functions

int yac_point_in_cell (double point_coords[3], struct yac_grid_cell cell)
 
int yac_point_in_cell2 (double point_coords[3], struct yac_grid_cell cell, struct bounding_circle bnd_circle)
 
static double get_angle (double a_lon, double b_lon)
 
static double get_angle_deg (double a_lon, double b_lon)
 
int yac_intersect_vec (enum yac_edge_type edge_type_a, double const a[3], double const b[3], enum yac_edge_type edge_type_b, double const c[3], double const d[3], double p[3], double q[3])
 
void yac_get_cell_bounding_circle (struct yac_grid_cell cell, struct bounding_circle *bnd_circle)
 
int yac_extents_overlap (struct bounding_circle *extent_a, struct bounding_circle *extent_b)
 
static double sq_len_diff_vec (double const a[3], double const b[3])
 computes square of the lenght of the vector ab
 
static double compute_sq_crd (struct sin_cos_angle angle)
 
static int yac_point_in_bounding_circle_vec (double point_vector[3], struct bounding_circle *bnd_circle)
 
static double clamp_abs_one (double val)
 
static void compute_sin_cos (double angle, double *sin_value, double *cos_value)
 
static void LLtoXYZ (double lon, double lat, double p_out[])
 
static void LLtoXYZ_deg (double lon, double lat, double p_out[])
 
static void XYZtoLL (double const p_in[], double *lon, double *lat)
 
static double det2_kahan (double a, double b, double c, double d)
 
static void crossproduct_kahan (double const a[], double const b[], double cross[])
 
static void crossproduct_d (const double a[], const double b[], double cross[])
 
static double get_vector_angle (double const a[3], double const b[3])
 
static struct sin_cos_angle sin_cos_angle_new (double sin, double cos)
 
static struct sin_cos_angle get_vector_angle_2 (double const a[3], double const b[3])
 
static int compare_angles (struct sin_cos_angle a, struct sin_cos_angle b)
 
static double sin_cos_angle_to_dble (struct sin_cos_angle angle)
 
static struct sin_cos_angle sum_angles_no_check (struct sin_cos_angle a, struct sin_cos_angle b)
 
static int sum_angles (struct sin_cos_angle a, struct sin_cos_angle b, struct sin_cos_angle *restrict sum)
 
static struct sin_cos_angle sub_angles_no_check (struct sin_cos_angle a, struct sin_cos_angle b)
 
static int sub_angles (struct sin_cos_angle a, struct sin_cos_angle b, struct sin_cos_angle *restrict sub)
 
static double compute_angle (struct sin_cos_angle angle)
 return angles in the range of [0;2PI[
 
static struct sin_cos_angle half_angle (struct sin_cos_angle angle)
 
static struct sin_cos_angle quarter_angle (struct sin_cos_angle angle)
 
static int points_are_identically (double const *a, double const *b)
 
static int compare_coords (double const *a, double const *b)
 
static void normalise_vector (double v[])
 
static void rotate_vector2 (double axis[], struct sin_cos_angle angle, double v_in[], double v_out[])
 
static void rotate_vector (double axis[], double angle, double v_in[], double v_out[])
 
void yac_triangulate_cell (struct yac_grid_cell cell, size_t start_corner, struct yac_grid_cell *triangles)
 
void yac_triangulate_cell_indices (size_t const *corner_indices, size_t num_corners, size_t start_corner, size_t(*triangle_indices)[3])
 
void yac_compute_bnd_triangle (double *vertices, size_t num_vertices, double triangle[][3], size_t num_tests)
 
int yac_circle_intersect (struct yac_circle a, struct yac_circle b, double p[3], double q[3])
 
int yac_point_on_edge (double p[3], double const a[3], double const b[3], enum yac_circle_type circle_type)
 

Variables

static const struct sin_cos_angle SIN_COS_ZERO = {0.0, 1.0}
 
static const struct sin_cos_angle SIN_COS_TOL = {yac_angle_tol, yac_cos_angle_tol}
 
static const struct sin_cos_angle SIN_COS_LOW_TOL = {yac_angle_low_tol, yac_cos_angle_low_tol}
 
static const struct sin_cos_angle SIN_COS_M_PI_2 = {1.0, 0.0}
 
static const struct sin_cos_angle SIN_COS_M_PI = {0.0, -1.0}
 
static const struct sin_cos_angle SIN_COS_7_M_PI_4 = {-0.707106781186547524401, +0.707106781186547524401}
 

Macro Definition Documentation

◆ yac_angle_low_tol

#define yac_angle_low_tol   (1e-11)

Definition at line 29 of file geometry.h.

◆ yac_angle_tol

#define yac_angle_tol   (1e-9)

Definition at line 26 of file geometry.h.

◆ yac_cos_angle_low_tol

#define yac_cos_angle_low_tol   (1.0)

Definition at line 30 of file geometry.h.

◆ yac_cos_angle_tol

#define yac_cos_angle_tol   (0.9999999999999999995)

Definition at line 28 of file geometry.h.

◆ YAC_RAD

#define YAC_RAD   (0.01745329251994329576923690768489)

Definition at line 22 of file geometry.h.

◆ yac_sq_angle_tol

#define yac_sq_angle_tol   (1e-9 * 1e-9)

Definition at line 27 of file geometry.h.

Enumeration Type Documentation

◆ yac_circle_type

Enumerator
GREAT_CIRCLE 
LAT_CIRCLE 
LON_CIRCLE 
POINT 

Definition at line 59 of file geometry.h.

Function Documentation

◆ clamp_abs_one()

static double clamp_abs_one ( double val)
inlinestatic

Definition at line 208 of file geometry.h.

Here is the caller graph for this function:

◆ compare_angles()

static int compare_angles ( struct sin_cos_angle a,
struct sin_cos_angle b )
inlinestatic

Definition at line 389 of file geometry.h.

Here is the caller graph for this function:

◆ compare_coords()

static int compare_coords ( double const * a,
double const * b )
inlinestatic

compares two 3d coordinates (vectors need to have a length of 1.0)

Parameters
[in]acoordinates of point a
[in]bcoordinates of point b
Returns
0 if points are identical, otherwise -1 or 1 depending on their relation

Definition at line 623 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_angle()

static double compute_angle ( struct sin_cos_angle angle)
inlinestatic

return angles in the range of [0;2PI[

Definition at line 533 of file geometry.h.

Here is the caller graph for this function:

◆ compute_sin_cos()

static void compute_sin_cos ( double angle,
double * sin_value,
double * cos_value )
inlinestatic

compute the sine and cosine of a provided angle in RAD (avoids values close to zero and ensures that the result is in the range [-1,1])

Parameters
[in]angleangle in the range of [-PI;PI]
[out]sin_value
[out]cos_value

Definition at line 220 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ compute_sq_crd()

static double compute_sq_crd ( struct sin_cos_angle angle)
inlinestatic

Definition at line 185 of file geometry.h.

Here is the caller graph for this function:

◆ crossproduct_d()

static void crossproduct_d ( const double a[],
const double b[],
double cross[] )
inlinestatic

for small angles <= 1e-?8? the crossproduct is inaccurate
use crossproduct_kahan for these cases

Definition at line 312 of file geometry.h.

Here is the caller graph for this function:

◆ crossproduct_kahan()

static void crossproduct_kahan ( double const a[],
double const b[],
double cross[] )
inlinestatic

Definition at line 297 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ det2_kahan()

static double det2_kahan ( double a,
double b,
double c,
double d )
inlinestatic

Definition at line 290 of file geometry.h.

Here is the caller graph for this function:

◆ get_angle()

static double get_angle ( double a_lon,
double b_lon )
inlinestatic

computes the angle between two longitude coordinates (in rad)
takes into account that longitude have a period of 2 pi

Parameters
[in]a_lon
[in]b_lon
Returns
angle between both coordinates (in rad)

Definition at line 110 of file geometry.h.

Here is the caller graph for this function:

◆ get_angle_deg()

static double get_angle_deg ( double a_lon,
double b_lon )
inlinestatic

computes the angle between two longitude coordinates (in deg)
takes into account that longitude have a period of 360

Parameters
[in]a_lon
[in]b_lon
Returns
angle between both coordinates (in rad)

Definition at line 126 of file geometry.h.

Here is the caller graph for this function:

◆ get_vector_angle()

static double get_vector_angle ( double const a[3],
double const b[3] )
inlinestatic

computes the great circle distance in rad for two points given in xyz coordinates taken from http://johnblackburne.blogspot.de/2012/05/angle-between-two-3d-vectors.html

Parameters
[in]apoint coordinates of point a
[in]bpoint coordinates of point b
Returns
great circle distance in rad between both points

Definition at line 329 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_vector_angle_2()

static struct sin_cos_angle get_vector_angle_2 ( double const a[3],
double const b[3] )
inlinestatic

Definition at line 376 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ half_angle()

static struct sin_cos_angle half_angle ( struct sin_cos_angle angle)
inlinestatic

computes angle / 2 The basic idea is to imagin angle being a vector v with (cos(x); sin(x)) and w being a vector with (1.0; 0.0). The normalised sum of v and w gives us v_h with (cos(x/2); sin(x/2)). For quadrants 2, 3, and 4 we have to apply some little tricks for higher accuracy.

Definition at line 561 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LLtoXYZ()

static void LLtoXYZ ( double lon,
double lat,
double p_out[] )
inlinestatic

converts lon-lat coordinates into xyz ones

Further information: http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations

Parameters
[in]lonlongitude coordinates in radian
[in]latlatitude coordinates in radian
[out]p_outxyz coordinates

Definition at line 249 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LLtoXYZ_deg()

static void LLtoXYZ_deg ( double lon,
double lat,
double p_out[] )
inlinestatic

converts lon-lat coordinates into xyz ones

Parameters
[in]lonlongitude coordinates in deg
[in]latlatitude coordinates in deg
[out]p_outxyz coordinates

Definition at line 269 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ normalise_vector()

static void normalise_vector ( double v[])
inlinestatic

normalises a vector

Definition at line 650 of file geometry.h.

Here is the caller graph for this function:

◆ points_are_identically()

static int points_are_identically ( double const * a,
double const * b )
inlinestatic

determines whether two given points are (nearly) identically

Parameters
[in]apoint coordinates of point a
[in]bpoint coordinates of point b
Returns
true if both points are (nearly) identically

Definition at line 609 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ quarter_angle()

static struct sin_cos_angle quarter_angle ( struct sin_cos_angle angle)
inlinestatic

computes angle / 4 I derived it based on half_angle

Definition at line 578 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotate_vector()

static void rotate_vector ( double axis[],
double angle,
double v_in[],
double v_out[] )
inlinestatic

rotate vector v_in around the given axis by a given angle

Parameters
[in]axisaxis around which v_in is to rotated
[in]anglerotation angle
[in]v_invector to be rotated
[out]v_outrotated vector

Definition at line 693 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rotate_vector2()

static void rotate_vector2 ( double axis[],
struct sin_cos_angle angle,
double v_in[],
double v_out[] )
inlinestatic

rotate vector v_in around the given axis by a given angle

Parameters
[in]axisaxis around which v_in is to rotated
[in]anglerotation angle
[in]v_invector to be rotated
[out]v_outrotated vector

Definition at line 665 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sin_cos_angle_new()

static struct sin_cos_angle sin_cos_angle_new ( double sin,
double cos )
inlinestatic

Definition at line 366 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sin_cos_angle_to_dble()

static double sin_cos_angle_to_dble ( struct sin_cos_angle angle)
inlinestatic

this routine converts a struct sin_cos_angle into a double, which allows to easily compare angles 0: 0 <= angle < PI/4 => ret = 0 * M_SQRT1_2 + sin(angle) 1: PI/4 <= angle < 3*PI/4 => ret = 2 * M_SQRT1_2 - cos(angle) 2: 3*PI/4 <= angle < 5*PI/4 => ret = 4 * M_SQRT1_2 - sin(angle) 3: 5*PI/4 <= angle < 7*PI/4 => ret = 6 * M_SQRT1_2 + cos(angle) 4: 7*PI/4 <= angle < 2*PI => ret = 8 * M_SQRT1_2 + sin(angle)

Definition at line 466 of file geometry.h.

◆ sq_len_diff_vec()

static double sq_len_diff_vec ( double const a[3],
double const b[3] )
inlinestatic

computes square of the lenght of the vector ab

Definition at line 180 of file geometry.h.

Here is the caller graph for this function:

◆ sub_angles()

static int sub_angles ( struct sin_cos_angle a,
struct sin_cos_angle b,
struct sin_cos_angle *restrict sub )
inlinestatic

computes (a-b), if (a-b) <= 0, the result is (a-b+2*PI) a and be have to be in the range [0;2*PI[

Returns
1 if (a-b) < 0

Definition at line 519 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sub_angles_no_check()

static struct sin_cos_angle sub_angles_no_check ( struct sin_cos_angle a,
struct sin_cos_angle b )
inlinestatic

computes (a-b), if (a-b) < 0, the result is (a-b+2*PI) a and be have to be in the range [0;2*PI[

Definition at line 509 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sum_angles()

static int sum_angles ( struct sin_cos_angle a,
struct sin_cos_angle b,
struct sin_cos_angle *restrict sum )
inlinestatic

computes (a+b), if (a+b) >= 2*PI, the result is (a+b-2*PI) a and be have to be in the range [0;2*PI[

Returns
1 if (a+b) is >= 2*PI

Definition at line 495 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sum_angles_no_check()

static struct sin_cos_angle sum_angles_no_check ( struct sin_cos_angle a,
struct sin_cos_angle b )
inlinestatic

computes (a+b), if (a+b) >= 2*PI, the result is (a+b-2*PI) a and be have to be in the range [0;2*PI[

Definition at line 485 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ XYZtoLL()

static void XYZtoLL ( double const p_in[],
double * lon,
double * lat )
inlinestatic

converts lon-lat coordinates into xyz ones

Further information: http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations

Parameters
[in]p_inxyz coordinates
[out]lonlongitude coordinate in radian
[out]latlatitude coordinate in radian

Definition at line 283 of file geometry.h.

◆ yac_circle_intersect()

int yac_circle_intersect ( struct yac_circle a,
struct yac_circle b,
double p[3],
double q[3] )

Definition at line 266 of file intersection.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_compute_bnd_triangle()

void yac_compute_bnd_triangle ( double * vertices,
size_t num_vertices,
double triangle[][3],
size_t num_tests )

computes a spherical triangle that contains all given vertices, the algorithm tries to minimise the size of the triangle

Parameters
[in]verticesvertices that are supposed to be within the triangle
[in]num_verticesnumber of vertices in vertices
[out]trianglebounding triangle
[in]num_testswith increasing number of tests computation time and chance of smaller bounding triangle increases
Remarks
num_tests has to be > 0

Definition at line 99 of file bnd_triangle.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_extents_overlap()

int yac_extents_overlap ( struct bounding_circle * extent_a,
struct bounding_circle * extent_b )

checks whether two extents overlap

Parameters
[in]extent_abounding circle
[in]extent_bbounding circle
Returns
0 if the bounding circles do not overlap

Definition at line 533 of file bnd_circle.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_get_cell_bounding_circle()

void yac_get_cell_bounding_circle ( struct yac_grid_cell cell,
struct bounding_circle * bnd_circle )

gets the bounding circle for a grid cell

Parameters
[in]cellgrid cell (coordinates have to be in radian)
[out]bnd_circlebounding circle of the grid cell

Definition at line 422 of file bnd_circle.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_intersect_vec()

int yac_intersect_vec ( enum yac_edge_type edge_type_a,
double const a[3],
double const b[3],
enum yac_edge_type edge_type_b,
double const c[3],
double const d[3],
double p[3],
double q[3] )

computes the intersection points of two edges

Parameters
[in]edge_type_atype of edge a
[in]afirst point of edge a
[in]bsecond point of edge a
[in]edge_type_btype of edge b
[in]cfirst point of edge b
[in]dsecond point of edge b
[out]pfirst intersection point
[out]qsecond intersection point
Returns
0 if the intersection points are neither on edge a or b
-1 if the two circles do not intersect
1st bit will be set if p is on edge a
2nd bit will be set if q is on edge a
3rd bit will be set if p is on edge b
4th bit will be set if q is on edge b
5th bit will be set if both circles are identically
Remarks
if -1 is returned neither p or q is set
if the two circles only have one intersection point, p and q will be identically, but only the p bits will be set

Definition at line 763 of file intersection.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_point_in_bounding_circle_vec()

static int yac_point_in_bounding_circle_vec ( double point_vector[3],
struct bounding_circle * bnd_circle )
inlinestatic

checks whether a point is within a bounding circle

Parameters
[in]point_vectorpoint to be checked
[in]bnd_circlebounding circle
Returns
0 if point is not within the bounding circle

Definition at line 197 of file geometry.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_point_in_cell()

int yac_point_in_cell ( double point_coords[3],
struct yac_grid_cell cell )

checks whether a given point is within a given cell

Parameters
[in]point_coords
[in]cell
Returns
0 if the point is not in the cell

Definition at line 465 of file check_overlap.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_point_in_cell2()

int yac_point_in_cell2 ( double point_coords[3],
struct yac_grid_cell cell,
struct bounding_circle bnd_circle )

checks whether a given point is within a given cell

Parameters
[in]point_coords
[in]cell
[in]bnd_circle
Returns
0 if the point is not in the cell

Definition at line 474 of file check_overlap.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_point_on_edge()

int yac_point_on_edge ( double p[3],
double const a[3],
double const b[3],
enum yac_circle_type circle_type )

Definition at line 860 of file intersection.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_triangulate_cell()

void yac_triangulate_cell ( struct yac_grid_cell cell,
size_t start_corner,
struct yac_grid_cell * triangles )

splits given cell into triangles

Parameters
[in]cellcell to be triangulated
[in]start_cornerstart algorithm at corner with this index (0 <= start_corner < n; with n being number of cell corners)
[out]trianglestriangles that are the result of the triangulation
Remarks
the user needs to provide (n-2) initialised grid_cells for the argument triangles (n being the number of cell corners of the cell)
this routine currently only works for convex grid cells
the algorithm ignores that actual edge types for cells with more than 3 corners and assumes them to be great circle edges

Definition at line 66 of file grid_cell.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ yac_triangulate_cell_indices()

void yac_triangulate_cell_indices ( size_t const * corner_indices,
size_t num_corners,
size_t start_corner,
size_t(*) triangle_indices[3] )

splits given indices of a cell into triangles

Parameters
[in]corner_indicescell corner indices to be triangulated
[in]num_cornersnumber of corners of the cell
[in]start_cornerstart algorithm at corner with this index (0 <= start_corner < n; with n being number of cell corners)
[out]triangle_indicestriangle indices that are the result of the triangulation
Remarks
the user needs to provide provide an array of size 3*(num_corners-2) for the argument triangle_indices

Definition at line 144 of file grid_cell.c.

Here is the caller graph for this function:

Variable Documentation

◆ SIN_COS_7_M_PI_4

const struct sin_cos_angle SIN_COS_7_M_PI_4 = {-0.707106781186547524401, +0.707106781186547524401}
static

Definition at line 42 of file geometry.h.

◆ SIN_COS_LOW_TOL

const struct sin_cos_angle SIN_COS_LOW_TOL = {yac_angle_low_tol, yac_cos_angle_low_tol}
static

Definition at line 38 of file geometry.h.

◆ SIN_COS_M_PI

const struct sin_cos_angle SIN_COS_M_PI = {0.0, -1.0}
static

Definition at line 41 of file geometry.h.

◆ SIN_COS_M_PI_2

const struct sin_cos_angle SIN_COS_M_PI_2 = {1.0, 0.0}
static

Definition at line 40 of file geometry.h.

◆ SIN_COS_TOL

const struct sin_cos_angle SIN_COS_TOL = {yac_angle_tol, yac_cos_angle_tol}
static

Definition at line 37 of file geometry.h.

◆ SIN_COS_ZERO

const struct sin_cos_angle SIN_COS_ZERO = {0.0, 1.0}
static

Definition at line 36 of file geometry.h.