Click here to Skip to main content
15,907,874 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Button color change Pin
Paulraj G29-Jul-08 21:03
Paulraj G29-Jul-08 21:03 
QuestionXSLT in VC++ Pin
vinay_K29-Jul-08 1:24
vinay_K29-Jul-08 1:24 
AnswerRe: XSLT in VC++ Pin
CPallini29-Jul-08 1:43
mveCPallini29-Jul-08 1:43 
GeneralRe: XSLT in VC++ Pin
vinay_K29-Jul-08 1:47
vinay_K29-Jul-08 1:47 
GeneralRe: XSLT in VC++ Pin
CPallini29-Jul-08 1:53
mveCPallini29-Jul-08 1:53 
GeneralRe: XSLT in VC++ Pin
vinay_K29-Jul-08 2:04
vinay_K29-Jul-08 2:04 
GeneralRe: XSLT in VC++ Pin
CPallini29-Jul-08 8:16
mveCPallini29-Jul-08 8:16 
QuestionDetermining if a GPS point is inside a polygon Pin
AaronM_NZ29-Jul-08 0:56
AaronM_NZ29-Jul-08 0:56 
Sorry if this is in the wrong forum, but I didnt think it would fit in the others! I have been attempting to convert a small bit of C to VB from this site: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html[^]

It determines if a given point is either inside, outside, or on the edge, of a polygon shape. I want to use this in a GPS mapping application I am working on, but its not working, I think I have some of the syntax slightly wrong.

The code to convert:

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{
  int i, j, c = 0;
  for (i = 0, j = nvert-1; i < nvert; j = i++) {
    if ( ((verty[i]>testy) != (verty[j]>testy)) &&
	 (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
       c = !c;
  }
  return c;
}

Here is what I have converted it to:
Function pnpoly(ByVal nvert As Int16, ByVal vertx() As Decimal, ByVal verty() As Decimal, ByVal testx As Decimal, ByVal testy As Decimal) As Int16

  ' RETURNS:
  ' -1 IF THE POINT IS OUTSIDE OF THE POLYGON,
  '  0 IF THE POINT IS ON AN EDGE OR AT A VERTEX,
  '  1 IF THE POINT IS INSIDE OF THE POLYGON

    Dim i As Int16 = 0
    Dim j As Int16 = 0
    Dim c As Int16 = 0

    i = 0
    j = nvert - 1
    Do
        If Not ((verty(i) > testy) = (verty(j) > testy)) Then
            If testx < (vertx(j) - vertx(i)) * (testy - verty(i)) / (verty(j) - verty(i)) + vertx(i) Then
                c = Not c
            End If
        End If
        j = i
        i = i + 1
    Loop Until Not i < nvert
    pnpoly = c
End Function

I have converted it based on notes in the source article, specifically:
in the C language, when executing the code a&&b, if a is false, then b must not be evaluated. If your compiler doesn't do this, then it's not implementing C, and you will get a divide-by-zero
and
Explanation of "for (i = 0, j = nvert-1; i < nvert; j = i++):"
The intention is to execute the loop for each i from 0 to nvert-1. For each iteration, j is i-1. However that wraps, so if i=0 then j=nvert-1. Therefore the current edge runs between verts j and i, and the loop is done once per edge. In detail:

1.Start by setting i and j:
i = 0
j = nvert-1
2. If i<nvert is false then exit the loop.
3. Do the loop body.
4. Set j=i and then
add 1 to i and then
5. Go back to step 2.


Have I done something obviously wrong? It just dosent return the results I am expecting! Here are the values I am passing to the function:

Dim xcoor(7) As Decimal
Dim ycoor(7) As Decimal
xcoor(0) = 2
ycoor(0) = 2
xcoor(1) = 5
ycoor(1) = 1
xcoor(2) = 8
ycoor(2) = 2
xcoor(3) = 7
ycoor(3) = 4
xcoor(4) = 8
ycoor(4) = 6
xcoor(5) = 1
ycoor(5) = 7
x = pnpoly(6, xcoor, ycoor, 3, 3)


Which should be drawing up a fairly basic polygon, and the point 3,3 is inside the polygon. No matter what coordinates I pass in to test, the function never returns 1 (inside).

Help!
AnswerRe: Determining if a GPS point is inside a polygon Pin
Iain Clarke, Warrior Programmer29-Jul-08 23:43
Iain Clarke, Warrior Programmer29-Jul-08 23:43 
GeneralRe: Determining if a GPS point is inside a polygon Pin
AaronM_NZ30-Jul-08 14:34
AaronM_NZ30-Jul-08 14:34 
AnswerRe: Determining if a GPS point is inside a polygon Pin
CPallini30-Jul-08 3:13
mveCPallini30-Jul-08 3:13 
GeneralRe: Determining if a GPS point is inside a polygon Pin
AaronM_NZ30-Jul-08 14:40
AaronM_NZ30-Jul-08 14:40 
GeneralYou are welcome Pin
CPallini30-Jul-08 20:52
mveCPallini30-Jul-08 20:52 
QuestionAbout C++ on different OS? Pin
ritz123429-Jul-08 0:35
ritz123429-Jul-08 0:35 
AnswerRe: About C++ on different OS? Pin
Cedric Moonen29-Jul-08 0:49
Cedric Moonen29-Jul-08 0:49 
GeneralRe: About C++ on different OS? Pin
toxcct29-Jul-08 0:57
toxcct29-Jul-08 0:57 
GeneralRe: About C++ on different OS? Pin
Cedric Moonen29-Jul-08 2:03
Cedric Moonen29-Jul-08 2:03 
JokeRe: About C++ on different OS? [THHB attempt] Pin
Rajesh R Subramanian29-Jul-08 2:32
professionalRajesh R Subramanian29-Jul-08 2:32 
JokeRe: About C++ on different OS? [THHB attempt] Pin
Cedric Moonen29-Jul-08 4:05
Cedric Moonen29-Jul-08 4:05 
GeneralRe: About C++ on different OS? [THHB attempt] Pin
Rajesh R Subramanian29-Jul-08 21:24
professionalRajesh R Subramanian29-Jul-08 21:24 
AnswerRe: About C++ on different OS? Pin
toxcct29-Jul-08 0:52
toxcct29-Jul-08 0:52 
AnswerRe: About C++ on different OS? Pin
CPallini29-Jul-08 0:53
mveCPallini29-Jul-08 0:53 
AnswerRe: About C++ on different OS? Pin
vikas amin30-Jul-08 11:08
vikas amin30-Jul-08 11:08 
QuestionRunTime Error : The instruction at "0x00000000" referenced memory at "0x00000000". The memory could not be "read". Pin
ptr_Electron29-Jul-08 0:33
ptr_Electron29-Jul-08 0:33 
AnswerRe: RunTime Error : The instruction at "0x00000000" referenced memory at "0x00000000". The memory could not be "read". Pin
Cedric Moonen29-Jul-08 0:47
Cedric Moonen29-Jul-08 0:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.