PC Review


Reply
Thread Tools Rate Thread

Dim as Point

 
 
Brad
Guest
Posts: n/a
 
      15th Jan 2007
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


 
Reply With Quote
 
 
 
 
Brad
Guest
Posts: n/a
 
      15th Jan 2007
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" <(E-Mail Removed)> wrote in message
news:0D6CB1C4-B930-4A41-97BE-(E-Mail Removed)...
> 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
>>
>>
>>



 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      16th Jan 2007
I would see it used like this:

Option Explicit
Option Base 0
Private Type POINT
x As Double
y As Double
End Type

Sub Main()
Dim XP, YP, XP1, YP1
Dim poly() As POINT
Dim b As Boolean
Dim x As Double, y As Double
Dim i As Long, j As Long
ReDim poly(0 To 19)

' Polygon
XP = Array(0#, 1#, 1#, 0#, 0#, 1#, _
-0.5, -1#, -1#, -2#, -2.5, _
-2#, -1.5, -0.5, 1#, 1#, 0#, _
-0.5, -1#, -0.5)
YP = Array(0#, 0#, 1#, 1#, 2#, 3#, 2#, _
3#, 0#, -0.5, -1#, -1.5, -2#, _
-2#, -1.5, -1#, -0.5, -1#, _
-1#, -0.5)
' Test Points
XP1 = Array(0.5, 0.5, -0.5, 0.75, 0, _
-0.5, -1, -1.5, -2.25, 0.5, 0.5, -0.5)
YP1 = Array(0.5, 1.5, 1.5, 2.25, 2.01, _
2.5, -0.5, 0.5, -1, -0.25, -1.25, -2.5)

' writing to the worksheet is not required
' but supports graphing the data to verify

Cells(2,1) = "XP" : Cells(3, 1) = "YP"
Cells(4,1) = "XP1" : Cells(5,1) = "YP1"
Cells(2, 2).Resize(1, 20) = XP
Cells(3, 2).Resize(1, 20) = YP
Cells(4, 2).Resize(1, 12) = XP1
Cells(5, 2).Resize(1, 12) = YP1
j = 0
For i = LBound(XP) To UBound(XP)
poly(j).x = XP(i)
poly(j).y = YP(i)
j = j + 1
Next

j = 1
For i = LBound(XP1) To UBound(XP1)
x = XP1(i): y = YP1(i)
b = pnpoly(20, poly, x, y)
Cells(6, j).Offset(0, 1) = b
j = j + 1
Next

End Sub

Function pnpoly(npol As Integer, poly() As POINT, _
x As Double, y As Double) As Boolean
Dim inpoly As Boolean
Dim i As Integer, 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

Note that I have changed the function a little to support the data used.
(integer=>double)


See description at:
http://tinyurl.com/y93rhr

or "spelled out"

http://209.85.165.104/search?q=cache...s&ct=clnk&cd=5

--
Regards,
Tom Ogilvy


"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:0D6CB1C4-B930-4A41-97BE-(E-Mail Removed)...
>> 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
>>>
>>>
>>>

>
>



 
Reply With Quote
 
Brad
Guest
Posts: n/a
 
      16th Jan 2007
Tom, thanks so much! Brad


"Tom Ogilvy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I would see it used like this:
>
> Option Explicit
> Option Base 0
> Private Type POINT
> x As Double
> y As Double
> End Type
>
> Sub Main()
> Dim XP, YP, XP1, YP1
> Dim poly() As POINT
> Dim b As Boolean
> Dim x As Double, y As Double
> Dim i As Long, j As Long
> ReDim poly(0 To 19)
>
> ' Polygon
> XP = Array(0#, 1#, 1#, 0#, 0#, 1#, _
> -0.5, -1#, -1#, -2#, -2.5, _
> -2#, -1.5, -0.5, 1#, 1#, 0#, _
> -0.5, -1#, -0.5)
> YP = Array(0#, 0#, 1#, 1#, 2#, 3#, 2#, _
> 3#, 0#, -0.5, -1#, -1.5, -2#, _
> -2#, -1.5, -1#, -0.5, -1#, _
> -1#, -0.5)
> ' Test Points
> XP1 = Array(0.5, 0.5, -0.5, 0.75, 0, _
> -0.5, -1, -1.5, -2.25, 0.5, 0.5, -0.5)
> YP1 = Array(0.5, 1.5, 1.5, 2.25, 2.01, _
> 2.5, -0.5, 0.5, -1, -0.25, -1.25, -2.5)
>
> ' writing to the worksheet is not required
> ' but supports graphing the data to verify
>
> Cells(2,1) = "XP" : Cells(3, 1) = "YP"
> Cells(4,1) = "XP1" : Cells(5,1) = "YP1"
> Cells(2, 2).Resize(1, 20) = XP
> Cells(3, 2).Resize(1, 20) = YP
> Cells(4, 2).Resize(1, 12) = XP1
> Cells(5, 2).Resize(1, 12) = YP1
> j = 0
> For i = LBound(XP) To UBound(XP)
> poly(j).x = XP(i)
> poly(j).y = YP(i)
> j = j + 1
> Next
>
> j = 1
> For i = LBound(XP1) To UBound(XP1)
> x = XP1(i): y = YP1(i)
> b = pnpoly(20, poly, x, y)
> Cells(6, j).Offset(0, 1) = b
> j = j + 1
> Next
>
> End Sub
>
> Function pnpoly(npol As Integer, poly() As POINT, _
> x As Double, y As Double) As Boolean
> Dim inpoly As Boolean
> Dim i As Integer, 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
>
> Note that I have changed the function a little to support the data used.
> (integer=>double)
>
>
> See description at:
> http://tinyurl.com/y93rhr
>
> or "spelled out"
>
> http://209.85.165.104/search?q=cache...s&ct=clnk&cd=5
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Brad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:0D6CB1C4-B930-4A41-97BE-(E-Mail Removed)...
>>> 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
>>>>
>>>>
>>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to recenter the form on the screen at some point other then startup. dr Microsoft Dot NET 1 18th Feb 2007 06:56 PM
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to recenter the form on the screen at some point other then startup. dr Microsoft C# .NET 1 18th Feb 2007 08:58 AM
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to recenter the form on the screen at some point other then startup. dr Microsoft VB .NET 1 18th Feb 2007 05:34 AM
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to recenter the form on the screen at some point other then startup. dr Microsoft Dot NET Framework 0 18th Feb 2007 05:24 AM
WANTED: Simple-to-understand, point-by-point guide to networking WindowsXP Pro Odie Ferrous Windows XP Networking 7 31st Oct 2003 10:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:10 PM.