PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ define_plane()

int define_plane ( POINTARRAY pa,
PLANE3D pl 
)

Here we define the plane of a polygon (boundary pointarray of a polygon) the plane is stored as a pont in plane (plane.pop) and a normal vector (plane.pv)

Definition at line 1137 of file measures3d.c.

References get_3dcross_product(), get_3dvector_from_points(), getPoint3dz_p(), LW_FALSE, POINTARRAY::npoints, rect_node::p1, rect_node::p2, PLANE3D::pop, PLANE3D::pv, VECTORLENGTH, VECTOR3D::x, POINT3DZ::x, VECTOR3D::y, POINT3DZ::y, VECTOR3D::z, and POINT3DZ::z.

Referenced by lw_dist3d_line_poly(), lw_dist3d_point_poly(), and lw_dist3d_poly_poly().

1138 {
1139  int i,j, numberofvectors, pointsinslice;
1140  POINT3DZ p, p1, p2;
1141 
1142  double sumx=0;
1143  double sumy=0;
1144  double sumz=0;
1145  double vl; /*vector length*/
1146 
1147  VECTOR3D v1, v2, v;
1148 
1149  if((pa->npoints-1)==3) /*Triangle is special case*/
1150  {
1151  pointsinslice=1;
1152  }
1153  else
1154  {
1155  pointsinslice=(int) floor((pa->npoints-1)/4); /*divide the pointarray into 4 slices*/
1156  }
1157 
1158  /*find the avg point*/
1159  for (i=0;i<(pa->npoints-1);i++)
1160  {
1161  getPoint3dz_p(pa, i, &p);
1162  sumx+=p.x;
1163  sumy+=p.y;
1164  sumz+=p.z;
1165  }
1166  pl->pop.x=(sumx/(pa->npoints-1));
1167  pl->pop.y=(sumy/(pa->npoints-1));
1168  pl->pop.z=(sumz/(pa->npoints-1));
1169 
1170  sumx=0;
1171  sumy=0;
1172  sumz=0;
1173  numberofvectors= floor((pa->npoints-1)/pointsinslice); /*the number of vectors we try can be 3, 4 or 5*/
1174 
1175  getPoint3dz_p(pa, 0, &p1);
1176  for (j=pointsinslice;j<pa->npoints;j+=pointsinslice)
1177  {
1178  getPoint3dz_p(pa, j, &p2);
1179 
1180  if (!get_3dvector_from_points(&(pl->pop), &p1, &v1) || !get_3dvector_from_points(&(pl->pop), &p2, &v2))
1181  return LW_FALSE;
1182  /*perpendicular vector is cross product of v1 and v2*/
1183  if (!get_3dcross_product(&v1,&v2, &v))
1184  return LW_FALSE;
1185  vl=VECTORLENGTH(v);
1186  sumx+=(v.x/vl);
1187  sumy+=(v.y/vl);
1188  sumz+=(v.z/vl);
1189  p1=p2;
1190  }
1191  pl->pv.x=(sumx/numberofvectors);
1192  pl->pv.y=(sumy/numberofvectors);
1193  pl->pv.z=(sumz/numberofvectors);
1194 
1195  return 1;
1196 }
double z
Definition: liblwgeom.h:333
double y
Definition: liblwgeom.h:333
double x
Definition: liblwgeom.h:333
double z
Definition: measures3d.h:51
int npoints
Definition: liblwgeom.h:370
VECTOR3D pv
Definition: measures3d.h:58
#define VECTORLENGTH(v)
Definition: measures3d.h:32
double y
Definition: measures3d.h:51
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:332
#define LW_FALSE
Definition: liblwgeom.h:76
static int get_3dvector_from_points(POINT3DZ *p1, POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.c:45
POINT3DZ pop
Definition: measures3d.h:57
double x
Definition: measures3d.h:51
static int get_3dcross_product(VECTOR3D *v1, VECTOR3D *v2, VECTOR3D *v)
Definition: measures3d.c:55
Here is the call graph for this function:
Here is the caller graph for this function: