Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Windows.Forms;
#endregion
Namespace P_polygon
{
Partial class Form1:form
{
Public Form1 ()
{
InitializeComponent ();
}
public int count = 0;//Vertex count
public bool reset=false;//set reset function mark
Private struct point//vertex structure
{
public float x, y;
}
Point[] pt = new POINT[100];
Private float Max (float x,float y)
{
return (X>Y?X:Y);
}
Private float Min (float x, float y)
{
return (x < y x:y);
}
private void Judge (point[] PT)//Judgment function
{
float Px = float. Parse (TextBox1.Text);
float Py = float. Parse (TextBox2.Text);
Float[] line = new float[99];
float Linelast;
Float flag = 1;//To determine the number of flags in line or so (greater than 0 on the right, less than 0 in the left)
BOOL online = false;
for (int i = 1; i < count; i++)
{
Line[i-1] = (PT[I].Y-PT[I-1].Y) * Px + (pt[i-1].x-pt[i].x) * Py +
(pt[i].x-pt[i-1].x) * pt[i-1].y-(PT[I].Y-PT[I-1].Y) * pt[i-1].x;
if (line[i-1] = = 0 && px <= Max (pt[i].x, pt[i-1].x) && Px >= Min (pt[i].x, pt[i-1].x))
Online = true;
Flag *= Line[i-1];
if (i = = count-1)
{
Linelast = (pt[0].y-pt[i].y) * Px + (pt[i].x-pt[0].x) * Py +
(pt[0].x-pt[i].x) * pt[i].y-(PT[0].Y-PT[I].Y) * pt[i].x;
Flag *= Linelast;
if (flag = 0)
{
if (Px <= Max (pt[i].x, pt[0].x) && Py >= Min (pt[i].x, pt[0].x))
Online = true;
Else
Online = false;
}
}
if ((Flag < 0 && online = false) | | (flag = = 0 && online = false))
{
MessageBox.Show ("The isolated point is outside the polygon");
Break
}
else if (flag = 0 && i = count-1 && online = True)
{
MessageBox.Show ("The isolated point is on the border of the Polygon");
Break
}
else if (flag > 0 && i = = count-1)
{
MessageBox.Show ("The isolated point is inside the polygon");
Break
}
private void Button4_Click (object sender, EventArgs e)
{
MessageBox.Show ("When you input the coordinates of vertexes,\nyou must ensure this vertexes are ordinal\nand the Polyg ' On ' right side of the ' Line\nfrom PREVIOUS vertex to current vertex.\nor else, there must as Error!\n\nplease mber! Good Luck!\n\n\npoint & Polygon v1.0 <<iceboy 2005.1.2>> ",
"attention!", messageboxbuttons.ok,messageboxicon.information);
}
}
}
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.