PostGIS  2.1.10dev-r@@SVN_REVISION@@
 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 923 of file measures3d.c.

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

924 {
925  int i,j, numberofvectors, pointsinslice;
926  POINT3DZ p, p1, p2;
927
928  double sumx=0;
929  double sumy=0;
930  double sumz=0;
931  double vl; /*vector length*/
932
933  VECTOR3D v1, v2, v;
934
935  if((pa->npoints-1)==3) /*Triangle is special case*/
936  {
937  pointsinslice=1;
938  }
939  else
940  {
941  pointsinslice=(int) floor((pa->npoints-1)/4); /*divide the pointarray into 4 slices*/
942  }
943
944  /*find the avg point*/
945  for (i=0;i<(pa->npoints-1);i++)
946  {
947  getPoint3dz_p(pa, i, &p);
948  sumx+=p.x;
949  sumy+=p.y;
950  sumz+=p.z;
951  }
952  pl->pop.x=(sumx/(pa->npoints-1));
953  pl->pop.y=(sumy/(pa->npoints-1));
954  pl->pop.z=(sumz/(pa->npoints-1));
955
956  sumx=0;
957  sumy=0;
958  sumz=0;
959  numberofvectors= floor((pa->npoints-1)/pointsinslice); /*the number of vectors we try can be 3, 4 or 5*/
960
961  getPoint3dz_p(pa, 0, &p1);
962  for (j=pointsinslice;j<pa->npoints;j+=pointsinslice)
963  {
964  getPoint3dz_p(pa, j, &p2);
965
966  if (!get_3dvector_from_points(&(pl->pop), &p1, &v1) || !get_3dvector_from_points(&(pl->pop), &p2, &v2))
967  return LW_FALSE;
968  /*perpendicular vector is cross product of v1 and v2*/
969  if (!get_3dcross_product(&v1,&v2, &v))
970  return LW_FALSE;
971  vl=VECTORLENGTH(v);
972  sumx+=(v.x/vl);
973  sumy+=(v.y/vl);
974  sumz+=(v.z/vl);
975  p1=p2;
976  }
977  pl->pv.x=(sumx/numberofvectors);
978  pl->pv.y=(sumy/numberofvectors);
979  pl->pv.z=(sumz/numberofvectors);
980
981  return 1;
982 }
double z
Definition: liblwgeom.h:290
double y
Definition: liblwgeom.h:290
double x
Definition: liblwgeom.h:290
double z
Definition: measures3d.h:36
int npoints
Definition: liblwgeom.h:327
VECTOR3D pv
Definition: measures3d.h:43
#define VECTORLENGTH(v)
Definition: measures3d.h:17
double y
Definition: measures3d.h:36
int getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *point)
Definition: lwgeom_api.c:305
#define LW_FALSE
Definition: liblwgeom.h:52
POINT3DZ pop
Definition: measures3d.h:42
int get_3dvector_from_points(POINT3DZ *p1, POINT3DZ *p2, VECTOR3D *v)
Definition: measures3d.h:85
double x
Definition: measures3d.h:36
int get_3dcross_product(VECTOR3D *v1, VECTOR3D *v2, VECTOR3D *v)
Definition: measures3d.h:95

Here is the call graph for this function:

Here is the caller graph for this function: