Thread: Dim as Point
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Brad Brad is offline
external usenet poster
 
Posts: 57
Default Dim as Point

Tom, thanks, but no, it has no declaration for "Point".... this is actually
just a bit of code that someone posted in response to a question regarding
determining whether an x-y point on a graph is inside or outside of a convex
polygon outlined on the same x-y graph.

The whole thing looks like this:

Function pnpoly(npol As Integer, poly() As Point, X As Integer, Y As
Integer) As Boolean
Dim inpoly As Boolean
Dim i, j As Integer

i = 0
j = npol - 1
inpoly = False
While (i < npol)
If ((((poly(i).Y <= Y) And (Y < poly(j).Y)) Or _
((poly(j).Y <= Y) And (Y < poly(i).Y)))) Then
If (X < (poly(j).X - poly(i).X) * (Y - poly(i).Y) / (poly(j).Y -
poly(i).Y) + poly(i).X) Then
inpoly = Not (inpoly)
End If
End If
j = i
i = i + 1
Wend
pnpoly = inpoly
End Function

Now, what I was actually trying to do was take Andy Pope's interesting
"bounding areas" chart where he draws bounding lines around two overlapping
convex polygons, and simply count the number of x-y points inside of and
outside of a polygon. So, I hunted around and found this code, referred to
generally as the crossing number algorithm, for just this sort of thing.
Most often what I found was listed as pseudo-code, but in this one case, a
snippet of VBA code. On the psuedo-code, it does have:

typedef struct (int x, y;) Point;

and I am certain this is most likely what you asked about.

I am still not sure how to apply it in the function above.... thanks, Brad




"Tom Ogilvy" wrote in message
...
Does he have a declaration at the top like:

Private Type POINT
x As Long
y As Long
End Type


Then point would be a structure that contains both and x and y coordinate.
with the declaration at the top of the module, then
Usage example:

Dim a() as point
for i = 1 to 10
a(i).x = int(rnd()*100 + 1)
a(i).y = int(rnd()*50 + 1)
Next

--
Regards,
Tom Ogilvy



"Brad" wrote:

For a bit of code where the author defines a function like this:

Function pnpoly(npol As Integer, poly() as Point, x as Integer, Y as
Integer) as Boolean,

I am pretty sure the poly() input defined "as Point" is looking for an xy
point value for an edge of a polygon, but I am unsure how it is derived.

Any ideas? My thanks in advance for any comments or suggestions... this
is a
function to identify whether an x-y data point falls inside of or outside
of
a convex polygon.

Cheers! Brad