|
YAC 3.18.0
Yet Another Coupler
|
#include "config.h"#include <math.h>#include <float.h>#include "yac_types.h"#include "grids/grid_cell.h"#include "utils_core.h"

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 void | product_eft (double a, double b, double *restrict product, double *restrict error) |
| static void | sum_eft (double a, double b, double *restrict sum, double *restrict error) |
| static void | accu_eft (double a, double *restrict accu, double *restrict error) |
| static void | accu_product_eft (double a, double b, double *restrict accu, double *restrict accu_error) |
| static void | det2_error (double a, double b, double c, double d, double *restrict det, double *restrict det_error) |
| 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 | dotproduct_eft (double const a[], double const b[]) |
| 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} |
| #define yac_angle_low_tol (1e-11) |
Definition at line 29 of file geometry.h.
| #define yac_angle_tol (1e-9) |
Definition at line 26 of file geometry.h.
| #define yac_cos_angle_low_tol (1.0) |
Definition at line 30 of file geometry.h.
| #define yac_cos_angle_tol (0.9999999999999999995) |
Definition at line 28 of file geometry.h.
| #define YAC_RAD (0.01745329251994329576923690768489) |
Definition at line 22 of file geometry.h.
| #define yac_sq_angle_tol (1e-9 * 1e-9) |
Definition at line 27 of file geometry.h.
| enum yac_circle_type |
| Enumerator | |
|---|---|
| GREAT_CIRCLE | |
| LAT_CIRCLE | |
| LON_CIRCLE | |
| POINT | |
Definition at line 59 of file geometry.h.
|
inlinestatic |
accumulates a value with error compensation using error-free transformation (EFT)
based on code by Hongyu Chen (https://github.com/hongyuchen1030/regridding-geom-benchmark)
| [in] | a | value to accumulate |
| [in,out] | accu | accumulator variable |
| [in,out] | error | accumulated rounding error |
Definition at line 334 of file geometry.h.

|
inlinestatic |
computes the product of two floating-point numbers and accumulates it with error compensation using error-free transformation (EFT)
This function multiplies a and b, then adds the result to the accumulator while tracking and compensating for rounding errors. This is useful for maintaining numerical precision in summations of products.
based on code by Hongyu Chen (https://github.com/hongyuchen1030/regridding-geom-benchmark)
| [in] | a | first factor |
| [in] | b | second factor |
| [in,out] | accu | accumulator variable |
| [in,out] | accu_error | accumulated rounding error |
Definition at line 357 of file geometry.h.


|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
compares two 3d coordinates (vectors need to have a length of 1.0)
| [in] | a | coordinates of point a |
| [in] | b | coordinates of point b |
Definition at line 731 of file geometry.h.


|
inlinestatic |
return angles in the range of [0;2PI[
Definition at line 641 of file geometry.h.
|
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])
| [in] | angle | angle in the range of [-PI;PI] |
| [out] | sin_value | |
| [out] | cos_value |
Definition at line 220 of file geometry.h.


|
inlinestatic |
|
inlinestatic |
for small angles <= 1e-?8? the crossproduct is inaccurate
use crossproduct_kahan for these cases
Definition at line 420 of file geometry.h.

|
inlinestatic |
Definition at line 405 of file geometry.h.


|
inlinestatic |
computes the determinant of a 2x2 matrix with error tracking using error-free transformation (EFT)
Computes det = a*d - b*c with accumulated rounding error
| [in] | a | element (0,0) of the matrix |
| [in] | b | element (0,1) of the matrix |
| [in] | c | element (1,0) of the matrix |
| [in] | d | element (1,1) of the matrix |
| [out] | det | determinant result (a*d - b*c) |
| [out] | det_error | accumulated rounding error of the computation |
Definition at line 382 of file geometry.h.


|
inlinestatic |
|
inlinestatic |
Computes the dot product of two vectors with error compensation using error-free transformation (EFT)
Definition at line 434 of file geometry.h.


|
inlinestatic |
computes the angle between two longitude coordinates (in rad)
takes into account that longitude have a period of 2 pi
| [in] | a_lon | |
| [in] | b_lon |
Definition at line 110 of file geometry.h.

|
inlinestatic |
computes the angle between two longitude coordinates (in deg)
takes into account that longitude have a period of 360
| [in] | a_lon | |
| [in] | b_lon |
Definition at line 126 of file geometry.h.

|
inlinestatic |
computes the great circle distance in rad for two points given in xyz coordinates
uses the following formula: angle = 2 * atan(|a-b|/|a+b|) (taken from “How Futile are Mindless Assessments of Roundoff in Floating-Point Computation?” by W. Kahan. https://people.eecs.berkeley.edu/~wkahan/Mindless.pdf)
In contrast to other formulas, this one provided the very good accuracy across all angles. An due to its simiple nature (no branching) also good performance.
| [in] | a | point coordinates of point a |
| [in] | b | point coordinates of point b |
Definition at line 463 of file geometry.h.

|
inlinestatic |
Definition at line 484 of file geometry.h.


|
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 669 of file geometry.h.


|
inlinestatic |
converts lon-lat coordinates into xyz ones
Further information: http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations
| [in] | lon | longitude coordinates in radian |
| [in] | lat | latitude coordinates in radian |
| [out] | p_out | xyz coordinates |
Definition at line 249 of file geometry.h.


|
inlinestatic |
converts lon-lat coordinates into xyz ones
| [in] | lon | longitude coordinates in deg |
| [in] | lat | latitude coordinates in deg |
| [out] | p_out | xyz coordinates |
Definition at line 269 of file geometry.h.


|
inlinestatic |
normalises a vector
Definition at line 743 of file geometry.h.

|
inlinestatic |
determines whether two given points are (nearly) identically
| [in] | a | point coordinates of point a |
| [in] | b | point coordinates of point b |
Definition at line 717 of file geometry.h.


|
inlinestatic |
computes the product of two floating-point numbers with error tracking using error-free transformation (EFT)
based on code by Hongyu Chen (https://github.com/hongyuchen1030/regridding-geom-benchmark)
| [in] | a | first factor |
| [in] | b | second factor |
| [out] | product | result of a * b |
| [out] | error | rounding error of the multiplication |
Definition at line 300 of file geometry.h.

|
inlinestatic |
computes angle / 4 I derived it based on half_angle
Definition at line 686 of file geometry.h.

|
inlinestatic |
rotate vector v_in around the given axis by a given angle
| [in] | axis | axis around which v_in is to rotated |
| [in] | angle | rotation angle |
| [in] | v_in | vector to be rotated |
| [out] | v_out | rotated vector |
Definition at line 786 of file geometry.h.


|
inlinestatic |
rotate vector v_in around the given axis by a given angle
| [in] | axis | axis around which v_in is to rotated |
| [in] | angle | rotation angle |
| [in] | v_in | vector to be rotated |
| [out] | v_out | rotated vector |
Definition at line 758 of file geometry.h.


|
inlinestatic |
Definition at line 474 of file geometry.h.


|
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 574 of file geometry.h.
|
inlinestatic |
computes square of the lenght of the vector ab
Definition at line 180 of file geometry.h.

|
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 627 of file geometry.h.


|
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 617 of file geometry.h.


|
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 603 of file geometry.h.


|
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 593 of file geometry.h.


|
inlinestatic |
computes the sum of two floating-point numbers with error tracking using error-free transformation (EFT)
based on code by Hongyu Chen (https://github.com/hongyuchen1030/regridding-geom-benchmark)
| [in] | a | first summand |
| [in] | b | second summand |
| [out] | sum | result of a + b |
| [out] | error | rounding error of the addition |
Definition at line 317 of file geometry.h.

|
inlinestatic |
converts lon-lat coordinates into xyz ones
Further information: http://en.wikipedia.org/wiki/List_of_common_coordinate_transformations
| [in] | p_in | xyz coordinates |
| [out] | lon | longitude coordinate in radian |
| [out] | lat | latitude coordinate in radian |
Definition at line 283 of file geometry.h.
| 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.


| 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
| [in] | vertices | vertices that are supposed to be within the triangle |
| [in] | num_vertices | number of vertices in vertices |
| [out] | triangle | bounding triangle |
| [in] | num_tests | with increasing number of tests computation time and chance of smaller bounding triangle increases |
Definition at line 99 of file bnd_triangle.c.


| int yac_extents_overlap | ( | struct bounding_circle * | extent_a, |
| struct bounding_circle * | extent_b ) |
checks whether two extents overlap
| [in] | extent_a | bounding circle |
| [in] | extent_b | bounding circle |
Definition at line 533 of file bnd_circle.c.


| void yac_get_cell_bounding_circle | ( | struct yac_grid_cell | cell, |
| struct bounding_circle * | bnd_circle ) |
gets the bounding circle for a grid cell
| [in] | cell | grid cell (coordinates have to be in radian) |
| [out] | bnd_circle | bounding circle of the grid cell |
Definition at line 422 of file bnd_circle.c.


| 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
| [in] | edge_type_a | type of edge a |
| [in] | a | first point of edge a |
| [in] | b | second point of edge a |
| [in] | edge_type_b | type of edge b |
| [in] | c | first point of edge b |
| [in] | d | second point of edge b |
| [out] | p | first intersection point |
| [out] | q | second intersection point |
Definition at line 763 of file intersection.c.


|
inlinestatic |
checks whether a point is within a bounding circle
| [in] | point_vector | point to be checked |
| [in] | bnd_circle | bounding circle |
Definition at line 197 of file geometry.h.


| int yac_point_in_cell | ( | double | point_coords[3], |
| struct yac_grid_cell | cell ) |
checks whether a given point is within a given cell
| [in] | point_coords | |
| [in] | cell |
Definition at line 465 of file check_overlap.c.


| 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
| [in] | point_coords | |
| [in] | cell | |
| [in] | bnd_circle |
Definition at line 474 of file check_overlap.c.


| 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.


| void yac_triangulate_cell | ( | struct yac_grid_cell | cell, |
| size_t | start_corner, | ||
| struct yac_grid_cell * | triangles ) |
splits given cell into triangles
| [in] | cell | cell to be triangulated |
| [in] | start_corner | start algorithm at corner with this index (0 <= start_corner < n; with n being number of cell corners) |
| [out] | triangles | triangles that are the result of the triangulation |
Definition at line 66 of file grid_cell.c.

| 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
| [in] | corner_indices | cell corner indices to be triangulated |
| [in] | num_corners | number of corners of the cell |
| [in] | start_corner | start algorithm at corner with this index (0 <= start_corner < n; with n being number of cell corners) |
| [out] | triangle_indices | triangle indices that are the result of the triangulation |
Definition at line 144 of file grid_cell.c.

|
static |
Definition at line 42 of file geometry.h.
|
static |
Definition at line 38 of file geometry.h.
|
static |
Definition at line 41 of file geometry.h.
|
static |
Definition at line 40 of file geometry.h.
|
static |
Definition at line 37 of file geometry.h.
|
static |
Definition at line 36 of file geometry.h.