# GIS algorithm-judgment point inside the plane

Source: Internet
Author: User

Main functions:

```// Obtain the void canalysedlg: getnotsame (carray

* Pointarray, int index, int indexs []) {indexs  = indexs  =-1; int size = pointarray-> getsize (); tabpoint buftpt, TPT; TPT = (tabpoint) pointarray-> getat (INDEX); For (INT I = index; I <size; I ++) {buftpt = (tabpoint) pointarray-> getat (I); If (buftpt. x! = TPT. x) {indexs  = I; break;} If (indexs  =-1) {for (INT I = 0; I <size; I ++) {buftpt = (tabpoint) pointarray-> getat (I); If (buftpt. x! = TPT. x) {indexs  = I; break ;}}for (Int J = index; j> = 0; j --) {buftpt = (tabpoint) pointarray-> getat (j); If (buftpt. x! = TPT. x) {indexs  = J; break ;}} if (indexs  =-1) {for (Int J = size-1; j> = 0; J --) {buftpt = (tabpoint) pointarray-> getat (j); If (buftpt. x! = TPT. x) {indexs  = J; break; }}} if (indexs  =-1 | indexs  =-1) {MessageBox ("a straight line exists in the region ");}}

// Determine whether the vertex is onlineBool canalysedlg: judgeptinline (tabpoint tpt1, tabpoint tpt2, tabpoint TPT){Double dx1 = getdistance (tpt1, tpt2 );Double dx2 = getdistance (TPT, tpt1 );Double dx3 = getdistance (TPT, tpt2 );Double dx = dx3 + dx2-dx1;
If (dx >=- 0.0000000001 & DX <= 0.0000000001){Return true;}Return false;}// Obtain the distance between two pointsDouble canalysedlg: getdistance (tabpoint tpt1, tabpoint tpt2){Double X = tpt1.x-tpt2.x;If (x <= 0){X =-X;}Double Y = tpt1.y-tpt2.y;If (Y <= 0){Y =-y;}
Return SQRT (x * x + y * y );}

// Determine the intersection// Return value: true: inside the plane; false: Outside the planeBool canalysedlg: judgemeetpoint (tabpoint TPT){Int meetpointnum = 0;// Obtain the number of feature entriesInt featuresize = m_featurearray.getsize ();For (INT I = 0; I <featuresize; I ++){Feature feature = (feature) m_featurearray.getat (I );// Obtain the number of feature partsInt featurepartsize = feature. partsize;For (Int J = 0; j <featurepartsize; j ++){Featurepart part = (featurepart) feature. partsarray-> getat (j );Int pointsize = part. pointsize;For (int K = 1; k

Getat (k-1 );
Tabpoint pt2 = (tabpoint) part. pointarray-> getat (k );

If (TPT. x <= pt1.x & TPT. x> = pt2.x) |(TPT. x> = pt1.x & TPT. x <= pt2.x ))&&(TPT. Y> = pt1.y | TPT. Y> = pt2.y )){// Determine whether the vertex is onlineIf (judgeptinline (pt1, pt2, TPT )){Return true;}
// Handle special cases where the intersection is the endpointDouble temp;// Temp is equivalent to the divisor (denominator of slope)Temp = pt1.x-pt2.x;If (temp> =-0.0000000001 & temp <= 0.0000000001){// Process the intersectionDouble dx = TPT. X-pt1.x;If (dx >=- 0.0000000001 & DX <= 0.0000000001){Int indexs  = {0, 0 };Getnotsame (part. pointarray, I, indexs );Tabpoint linept1, linept2;Linept1 = part. pointarray-> getat (indexs );Linept2 = part. pointarray-> getat (indexs );If (I> indexs ){Break;}Else{I = indexs  + 1;}If (TPT. Y> pt1.y & (TPT. x> = linept1.x & TPT. x <= linept2.x) |(TPT. x> = linept2.x & TPT. x <= linept1.x )))Meetpointnum ++;}}Else{Double KK, BB;Double meetpty, meetptx;Kk = (pt1.y-pt2.y)/(pt1.x-pt2.x );BB = pt1.y-kk * pt1.x;Meetpty = KK * TPT. x + BB;Meetptx = TPT. X;// Handle special cases where the intersection is the endpointDouble dx, Dy, dx2, dy2;DX = meetptx-pt1.x;DY = meetpty-pt1.y;Dx2 = meetptx-pt2.x;Dy2 = meetpty-pt2.y;If (dx> =-0.0000000001 & DX <= 0.0000000001 & dy> =-0.0000000001& Dy <= 0.0000000001 )){Tabpoint pt3;If (k = 1){Pt3 = (tabpoint) part. pointarray-> getat (pointsize-2 );}Else{Pt3 = (tabpoint) part. pointarray-> getat (K-2 );}// Extract the upper and lower points of the intersection point on both sides of the vertical lineIf (TPT. Y> meetpty & (meetptx> = pt3.x & meetptx <= pt2.x) |(Meetptx> = pt2.x & meetptx <= pt3.x )))Meetpointnum ++;} Else if (! (Dx2> =-0.0000000001 & dx2 <= 0.0000000001 & dy2> =-0.0000000001& Dy2 <= 0.0000000001 )){If (TPT. Y> meetpty)Meetpointnum ++;}}}}}}
If (meetpointnum % 2 = 1)Return true;ElseReturn false;}

```
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.