PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
measures3d.h
Go to the documentation of this file.
1/**********************************************************************
2 *
3 * PostGIS - Spatial Types for PostgreSQL
4 * http://postgis.net
5 *
6 * PostGIS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PostGIS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18 *
19 **********************************************************************
20 *
21 * Copyright 2011 Nicklas Avén
22 * Copyright 2019 Darafei Praliaskouski
23 *
24 **********************************************************************/
25
26#ifndef _MEASURES3D_H
27#define _MEASURES3D_H 1
28#include <float.h>
29#include "measures.h"
30
31#define DOT(u, v) ((u).x * (v).x + (u).y * (v).y + (u).z * (v).z)
32#define VECTORLENGTH(v) sqrt(((v).x * (v).x) + ((v).y * (v).y) + ((v).z * (v).z))
33
38typedef struct
39{
40 double distance; /*the distance between p1 and p2*/
43 int mode; /*the direction of looking, if thedir = -1 then we look for 3dmaxdistance and if it is 1 then we look
44 for 3dmindistance*/
45 int twisted; /*To preserve the order of incoming points to match the first and second point in 3dshortest and
46 3dlongest line*/
47 double tolerance; /*the tolerance for 3ddwithin and 3ddfullywithin*/
48} DISTPTS3D;
49
50typedef struct
51{
52 double x, y, z;
53} VECTOR3D;
54
55typedef struct
56{
57 POINT3DZ pop; /*Point On Plane*/
58 VECTOR3D pv; /*Perpendicular normal vector*/
59} PLANE3D;
60
61/*
62Geometry returning functions
63*/
64LWGEOM *lw_dist3d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode);
65LWGEOM *lw_dist3d_distanceline(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode);
66
67/*
68Preprocessing functions
69*/
70int lw_dist3d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl);
71int lw_dist3d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl);
72int lw_dist3d_distribute_fast(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl);
73
74/*
75Brute force functions
76*/
77int lw_dist3d_pt_ptarray(const POINT3DZ *p, const POINTARRAY *pa, DISTPTS3D *dl);
78int lw_dist3d_point_point(const LWPOINT *point1, const LWPOINT *point2, DISTPTS3D *dl);
79int lw_dist3d_point_line(const LWPOINT *point, const LWLINE *line, DISTPTS3D *dl);
80int lw_dist3d_point_poly(const LWPOINT *point, const LWPOLY *poly, DISTPTS3D *dl);
81int lw_dist3d_point_tri(const LWPOINT *point, const LWTRIANGLE *tri, DISTPTS3D *dl);
82
83int lw_dist3d_line_line(const LWLINE *line1, const LWLINE *line2, DISTPTS3D *dl);
84int lw_dist3d_line_poly(const LWLINE *line, const LWPOLY *poly, DISTPTS3D *dl);
85int lw_dist3d_line_tri(const LWLINE *line, const LWTRIANGLE *tri, DISTPTS3D *dl);
86
87int lw_dist3d_poly_poly(const LWPOLY *poly1, const LWPOLY *poly2, DISTPTS3D *dl);
88int lw_dist3d_poly_tri(const LWPOLY *poly, const LWTRIANGLE *tri, DISTPTS3D *dl);
89
90int lw_dist3d_tri_tri(const LWTRIANGLE *tri1, const LWTRIANGLE *tri2, DISTPTS3D *dl);
91
92int lw_dist3d_pt_pt(const POINT3DZ *p1, const POINT3DZ *p2, DISTPTS3D *dl);
93int lw_dist3d_pt_seg(const POINT3DZ *p, const POINT3DZ *A, const POINT3DZ *B, DISTPTS3D *dl);
94int lw_dist3d_pt_poly(const POINT3DZ *p, const LWPOLY *poly, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl);
95int lw_dist3d_pt_tri(const POINT3DZ *p, const LWTRIANGLE *tri, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl);
96
97int lw_dist3d_seg_seg(const POINT3DZ *A, const POINT3DZ *B, const POINT3DZ *C, const POINT3DZ *D, DISTPTS3D *dl);
98
99int lw_dist3d_ptarray_ptarray(const POINTARRAY *l1, const POINTARRAY *l2, DISTPTS3D *dl);
100int lw_dist3d_ptarray_poly(const POINTARRAY *pa, const LWPOLY *poly, PLANE3D *plane, DISTPTS3D *dl);
101int lw_dist3d_ptarray_tri(const POINTARRAY *pa, const LWTRIANGLE *tri, PLANE3D *plane, DISTPTS3D *dl);
102
103int define_plane(const POINTARRAY *pa, PLANE3D *pl);
104int pt_in_ring_3d(const POINT3DZ *p, const POINTARRAY *ring, PLANE3D *plane);
105
106/*
107Helper functions
108*/
109
110#endif /* !defined _MEASURES3D_H */
int pt_in_ring_3d(const POINT3DZ *p, const POINTARRAY *ring, PLANE3D *plane)
pt_in_ring_3d(): crossing number test for a point in a polygon input: p = a point,...
int lw_dist3d_line_line(const LWLINE *line1, const LWLINE *line2, DISTPTS3D *dl)
line to line calculation
Definition measures3d.c:826
int lw_dist3d_tri_tri(const LWTRIANGLE *tri1, const LWTRIANGLE *tri2, DISTPTS3D *dl)
triangle to triangle calculation
Definition measures3d.c:952
int lw_dist3d_line_tri(const LWLINE *line, const LWTRIANGLE *tri, DISTPTS3D *dl)
line to triangle calculation
Definition measures3d.c:854
int lw_dist3d_point_poly(const LWPOINT *point, const LWPOLY *poly, DISTPTS3D *dl)
Computes point to polygon distance For mindistance that means: 1) find the plane of the polygon 2) pr...
Definition measures3d.c:778
int lw_dist3d_pt_seg(const POINT3DZ *p, const POINT3DZ *A, const POINT3DZ *B, DISTPTS3D *dl)
If searching for min distance, this one finds the closest point on segment A-B from p.
int lw_dist3d_distribute_bruteforce(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This function distributes the brute-force for 3D so far the only type, tasks depending on type.
Definition measures3d.c:598
int lw_dist3d_seg_seg(const POINT3DZ *A, const POINT3DZ *B, const POINT3DZ *C, const POINT3DZ *D, DISTPTS3D *dl)
Finds the two closest points on two linesegments.
int lw_dist3d_line_poly(const LWLINE *line, const LWPOLY *poly, DISTPTS3D *dl)
line to polygon calculation
Definition measures3d.c:837
int lw_dist3d_pt_ptarray(const POINT3DZ *p, const POINTARRAY *pa, DISTPTS3D *dl)
search all the segments of pointarray to see which one is closest to p Returns distance between point...
Definition measures3d.c:996
int lw_dist3d_ptarray_ptarray(const POINTARRAY *l1, const POINTARRAY *l2, DISTPTS3D *dl)
Finds all combinations of segments between two pointarrays.
LWGEOM * lw_dist3d_distancepoint(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode)
Function initializing 3dclosestpoint calculations.
Definition measures3d.c:235
int lw_dist3d_pt_poly(const POINT3DZ *p, const LWPOLY *poly, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl)
Checking if the point projected on the plane of the polygon actually is inside that polygon.
int define_plane(const POINTARRAY *pa, PLANE3D *pl)
int lw_dist3d_ptarray_poly(const POINTARRAY *pa, const LWPOLY *poly, PLANE3D *plane, DISTPTS3D *dl)
Computes pointarray to polygon distance.
int lw_dist3d_point_tri(const LWPOINT *point, const LWTRIANGLE *tri, DISTPTS3D *dl)
Definition measures3d.c:804
int lw_dist3d_distribute_fast(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
int lw_dist3d_pt_pt(const POINT3DZ *p1, const POINT3DZ *p2, DISTPTS3D *dl)
Compares incoming points and stores the points closest to each other or most far away from each other...
LWGEOM * lw_dist3d_distanceline(const LWGEOM *lw1, const LWGEOM *lw2, int32_t srid, int mode)
Function initializing 3dshortestline and 3dlongestline calculations.
Definition measures3d.c:131
int lw_dist3d_pt_tri(const POINT3DZ *p, const LWTRIANGLE *tri, PLANE3D *plane, POINT3DZ *projp, DISTPTS3D *dl)
int lw_dist3d_point_point(const LWPOINT *point1, const LWPOINT *point2, DISTPTS3D *dl)
point to point calculation
Definition measures3d.c:739
int lw_dist3d_point_line(const LWPOINT *point, const LWLINE *line, DISTPTS3D *dl)
point to line calculation
Definition measures3d.c:755
int lw_dist3d_poly_tri(const LWPOLY *poly, const LWTRIANGLE *tri, DISTPTS3D *dl)
polygon to triangle calculation
Definition measures3d.c:911
int lw_dist3d_poly_poly(const LWPOLY *poly1, const LWPOLY *poly2, DISTPTS3D *dl)
polygon to polygon calculation
Definition measures3d.c:870
int lw_dist3d_ptarray_tri(const POINTARRAY *pa, const LWTRIANGLE *tri, PLANE3D *plane, DISTPTS3D *dl)
Computes pointarray to triangle distance.
int lw_dist3d_recursive(const LWGEOM *lwg1, const LWGEOM *lwg2, DISTPTS3D *dl)
This is a recursive function delivering every possible combination of subgeometries.
Definition measures3d.c:519
POINT3DZ p2
Definition measures3d.h:42
int twisted
Definition measures3d.h:45
POINT3DZ p1
Definition measures3d.h:41
double distance
Definition measures3d.h:40
double tolerance
Definition measures3d.h:47
Structure used in distance-calculations.
Definition measures3d.h:39
POINT3DZ pop
Definition measures3d.h:57
VECTOR3D pv
Definition measures3d.h:58
double x
Definition measures3d.h:52