C # + AE method for determining whether a vertex is in the plane

Source: Internet
Author: User
Tags ipoint

Overall Thinking: the shooting method. ①: First judge the relationship between the X and Y coordinates of the vertex and the xmin, xmax, ymin, and Ymax of the polygon. If these four values are exceeded, they must be outside the polygon; ②: If the above conditions are not met, continue. To the left side of a line segment, the X coordinate value of the Left vertex of the line segment must be smaller than xmin. Determine the intersection of a line segment and a polygon; If the intersection is an even number, it is outside the polygon. If the intersection is an odd number, it is inside the polygon; ③: Because the last intersection point is the intersection of the topological relationship according to ipolympus and polygon, and the intersection is an igeometry object, It redirects to the igeometrycollection object and finally gets a click ipointcollection, you can obtain the number of intersection points based on the pointcount attribute. To obtain the minimum X coordinate value:

Public double getxminvalue (ipolympus Gon npolygon)
{
Ipolympus Gon spolympus gon;
Spolympus Gon = npolygon;
Ipointcollection ppointcollection;
Ppointcollection = spolympus GON as ipointcollection;

Int n = ppointcollection. pointcount;
Double [] coordx = new double [N];

For (INT I = 0; I <n; I ++)
{
Ipoint point = ppointcollection. get_point (I );
Coordx [I] = point. X;
}
// Sort the array in ascending order
System. array. Sort (coordx );

Xmin = coordx [0];
Return xmin;
}

Draw a Ray to the left and obtain the number of intersectionsCode:

Try
{
 
Iline newline = new lineclass ();

Ipoint topoint = new pointclass ();
Topoint. putcoords (getxminvalue (ppolygon)-20.0000000000000, Ppoint. y );

Newline. putcoords (Ppoint, topoint); // assign the start coordinate to the new line

// Miao's ideas
Ipolympus L = new polylineclass ();
L. frompoint = Ppoint;
L. topoint = topoint;

Igeometrycollection ppolyline = new polylineclass ();
Isegmentcollection ppath;
Ppath = new pathclass ();
Object missing1 = type. missing;
Object missing2 = type. missing;

ppath. addsegment (newline as isegment, ref missing1, ref missing2);
ppolyline. addgeometry (ppath as igeometry, ref missing1, ref missing2);

Ielement element = drawlinesymbol (ppolyline as igeometry, pcolor );
Pgraph. addelement (element, 0 );
Pactiveview. partialrefresh (esriviewdrawphase. esriviewgraphics, null, null );


Itopologicaloperator ptopo = ppolygon as itopologicaloperator; // ppolygon Polygon
Igeometrycollection pgeocol = ptopo. Intersect (igeometry) L, esrigeometrydimension. esrigeometry0dimension) as igeometrycollection; // An error occurred while executing this sentence;
Ipointcollection ppointcol = pgeocol as ipointcollection;
If (ppointcol. pointcount) % 2 = 0)
{
MessageBox. Show ("the intersection of rays and polygon is:" + ppointcol. pointcount. tostring () + ", which is located outside the polygon. ");
}
Else
{
MessageBox. Show ("the number of intersections between the ray and the polygon is:" + ppointcol. pointcount. tostring () + ", and the point is within the polygon. ");
}

}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}

 

this article is based on the polygon object, so the overlap is not considered.

Contact Us

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.