Sie sind auf Seite 1von 2

CIVL 5110 VBA PROJECT

NAME: CHOW Jun Kang SID: 20020628

First of all, the “isinside” function is developed to check whether a point of interest, 𝑝𝑠 ,

lies inside a polygon drawn in the Microsoft Excel. If the 𝑝𝑠 lies inside a polygon, the

answer is TURE. On the other hand, a FALSE will be shown on the spreadsheet if the

𝑝𝑠 is outside the polygon specified.

Before using this function, a few assumptions are made to ensure it to work

efficiently and smoothly as follows: (1) Vertexes of the polygon are specified in

anticlockwise direction; (2) only a closed polygon is drawn, in other words, there are

no smaller polygons found within a larger polygon and; (3) only straight lines are drawn.

The “isinside” function requires four inputs; the first two inputs are the

coordinates of the 𝑝𝑠 , (𝑥𝑐 , 𝑦𝑐 ) and the remaining two inputs are the arrays representing

the x- and y-coordinates of the vertexes of polygon,

[𝑥𝑣1 , 𝑥𝑣2 , 𝑥𝑣3 , … , 𝑥𝑣𝑛 ; 𝑦𝑣1 , 𝑦𝑣2 , 𝑦𝑣3 , … , 𝑦𝑣𝑛 ] , respectively, where 𝑛 is the number of

vertex.

Generally, the identification of the location of 𝑝𝑠 is divided into three phases.

In the first phase, algorithm is designed to check whether (𝑥𝑐 , 𝑦𝑐 ) coincides with any

vertex of the polygon, v. For instance, if (𝑥𝑐 , 𝑦𝑐 ) = (𝑥𝑣𝑛 , 𝑦𝑣𝑛 ), the 𝑝𝑠 coincides with the

vertex of the n-side polygon; it is not inside the polygon, and in return a “FALSE”

response is shown.

Next, checking is done along the edges of the polygon. For a n-side polygon,

there are (n – 1) edges to be examined. If the 𝑝𝑠 lies on the edge, it divides the edge into

two parts, and the total length of these two parts is equal to the length of the original
edge. For example, if the 𝑝𝑠 lies between ith and (i + 1)th vertex, then

√(𝑥𝑐 − 𝑥𝑖 )2 + (𝑦𝑐 − 𝑦𝑖 )2 + √(𝑥𝑐 − 𝑥𝑖+1 )2 + (𝑦𝑐 − 𝑦𝑖+1 )2 = √(𝑥𝑖 − 𝑥𝑖+1 )2 + (𝑦𝑖 − 𝑦𝑖+1 )2 .

Therefore, in this case, a “FALSE” response is obtained since the 𝑝𝑠 does not lie inside

the polygon specified.

After checking whether the 𝑝𝑠 lies on the vertex or edge, the subsequent step is

to determine whether the 𝑝𝑠 is inside or outside the polygon. To achieve this goal, a

straight line is drawn between each vertex and 𝑝𝑠 . For example, for a n-side polygon, n

lines are drawn to connect each vertex with the 𝑝𝑠 . Then, the angles between two

adjacent vertexes are added up in an anti-clockwise direction. If the cross product

between the two lines is positive, a positive value is computed, and vice versa. In other

words, consider the acute or obtuse answer between two lines, l1 and l2, the angle is

considered as positive if l2 is anti-clockwise from l1. For the final answer, if the total of

all the angles is 2π or -2π, then the point is inside the polygon, and a “TRUE” response

is obtained. However, if the total is zero, this indicates the point is outside the polygon

specified, and a “FALSE” answer is shown on the spreadsheet.

In conclusion, a function is designed to check whether a point lies inside the

polygon specified. Following the assumptions made, this function could be used for

polygon with unrestricted number of vertexes and edges at any coordinates.

Das könnte Ihnen auch gefallen