News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Checking a point inside a polygon

Started by Farabi, May 21, 2009, 09:36:29 AM

Previous topic - Next topic

Farabi

Anyone know how to determine if a point(x,y) is inside a set of points?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

TmX


Farabi

Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

If j=i what is the different of polY and polY[j]? Anyone can explain?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

i and j are two points that are being tested
if you look at the first image on that page - then read the first paragraph
you can toss out his C code and write it in asm

@TmX - that looks like a cool site
i need a refresher in reading C - haven't had to look at it for years
now, trying to learn API functions - it seems all the examples are C
you guys can all take solice - if i were ceo of MS, all the examples would be in asm and we'd make the C guys figure it out - lol

oh - btw Farabi - make sure you include the possibility of polygons are larger than the display area

this looks like a good basis for a fill routine

EDIT:
i knew i saw this someplace
recursive fill
this one is written in basic  :red
http://www.wearmouth.demon.co.uk/gw03/basfill.htm

TmX

Quote from: Farabi on May 21, 2009, 10:41:39 AM
If j=i what is the different of polY and polY[j]? Anyone can explain?

no difference
but look, j have a constant value: polySides-1
while for i, you have to iterate from 0 to polySides

example:
polySides = 10
j = 9
i = 0,1,2,3,4,5,6,7,8,9

Farabi

Quote from: TmX on May 21, 2009, 12:38:36 PM
Quote from: Farabi on May 21, 2009, 10:41:39 AM
If j=i what is the different of polY and polY[j]? Anyone can explain?

no difference
but look, j have a constant value: polySides-1
while for i, you have to iterate from 0 to polySides

example:
polySides = 10
j = 9
i = 0,1,2,3,4,5,6,7,8,9

So j must remain 9 until the iteration is complete am I right?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

TmX

ah sorry, just recently re-read the code again

first, j is initialized as polySide-1
and during the iteration, j is updated by "j =i"

so j's value it's not constant...

jj2007

For the lazy programmer...

The PtInRegion function determines whether the specified point is inside the specified region.

BOOL PtInRegion(

    HRGN hrgn,   // handle of region
    int X,   // x-coordinate of point 
    int Y    // y-coordinate of point 
   );

Farabi

Quote from: jj2007 on May 21, 2009, 05:17:44 PM
For the lazy programmer...

The PtInRegion function determines whether the specified point is inside the specified region.

BOOL PtInRegion(

    HRGN hrgn,   // handle of region
    int X,   // x-coordinate of point 
    int Y    // y-coordinate of point 
   );

I'll try to use non-MS first, If Im stuck I guess I will use MS one.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Farabi

Here is my code so far

IsInsidePolygon proc uses esi edi x:dword,y:dword,lpPoints:dword,nPointCounts:dword
LOCAL i,j:dword
LOCAL oddNodes,logic:dword
; bool pointInPolygon() {
;
; int      i, j=polySides-1 ;
  ;boolean  oddNodes=NO      ;
;
;  for (i=0; i<polySides; i++) {
;    if (polyY[i]<y && polyY[j]>=y
;    ||  polyY[j]<y && polyY[i]>=y) {
;      if (polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x) {
;        oddNodes=!oddNodes; }}
;    j=i; }
;  return oddNodes; }

push nPointCounts
pop j
dec j

mov esi,lpPoints

xor eax,eax
mov i,eax
mov oddNodes,eax
loop_i:
mov eax,i
shl eax,3
mov ecx,[esi+eax].POINT.y ; POINT.y
cmp ecx,y
jnl pol_i
mov eax,j
shl eax,3
mov ecx,[esi+eax].POINT.y
cmp ecx,y
jnae pol_i
mov eax,j
shl eax,3
mov ecx,[esi+eax].POINT.y
cmp ecx,y
jnl pol_i
mov eax,i
shl eax,3
mov ecx,[esi+eax].POINT.y ; POINT.y
cmp ecx,y
jnae pol_i

pol_i:
inc i
mov eax,nPointCounts
cmp i,eax
jl loop_i

ret


And about if (polyX+(y-polyY)/(polyY[j]-polyY)*(polyX[j]-polyX)<x) What should I calculate first? Add everything first and then divide it I guess?
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

dedndave

Farabi, are you trying to see if it is a target hit ?

Farabi

Quote from: dedndave on May 22, 2009, 03:46:56 AM
Farabi, are you trying to see if it is a target hit ?


Yes.
Look this picture,



I want the user able to pick a polygon from the mouse and my app will crop it.

Here is the complete code, but it have not working yet. Mind to help?
Quote
IsInsidePolygon proc uses esi edi x:dword,y:dword,lpPoints:dword,nPointCounts:dword
   LOCAL i,j:dword
   LOCAL oddNodes,logic:dword
;   bool pointInPolygon() {
;
; int      i, j=polySides-1 ;
  ;boolean  oddNodes=NO      ;
;
;  for (i=0; i<polySides; i++) {
;    if (polyY<y && polyY[j]>=y
;    ||  polyY[j]<y && polyY>=y) {
;      if (polyX+(y-polyY)/(polyY[j]-polyY)*(polyX[j]-polyX)<x) {
;        oddNodes=!oddNodes; }}
;    j=i; }
;  return oddNodes; }
   
   push nPointCounts
   pop j
   dec j
   
   mov esi,lpPoints
   
   xor eax,eax
   mov i,eax
   mov oddNodes,eax
   loop_i:
      mov eax,i
      shl eax,3
      mov ecx,[esi+eax].POINT.y      ; POINT.y
      cmp ecx,y
      jnl pol_i
         mov eax,j
         shl eax,3
         mov ecx,[esi+eax].POINT.y
         cmp ecx,y
         jnae pol_i
            mov eax,j
            shl eax,3
            mov ecx,[esi+eax].POINT.y
            cmp ecx,y
            jnl pol_i
               mov eax,i
               shl eax,3
               mov ecx,[esi+eax].POINT.y      ; POINT.y
               cmp ecx,y
               jnae pol_i
                  ;      if (polyX+(y-polyY)/(polyY[j]-polyY)*(polyX[j]-polyX)<x)
                  mov eax,j
                  shl eax,3
                  mov ecx,[esi+eax].POINT.x
                  mov eax,i
                  shl eax,3
                  sub ecx,[esi+eax].POINT.x
                  push ecx                  ; esp=(polyX[j]-polyX)
                     mov eax,j
                     shl eax,3
                     mov ecx,[esi+eax].POINT.y
                     mov eax,i
                     shl eax,3
                     sub ecx,[esi+eax].POINT.y
                     xchg eax,ecx
                     mul dword ptr[esp]
                  pop ecx
                  push eax                  ; esp=(polyY[j]-polyY)*(polyX[j]-polyX)
                     push y
                        mov eax,i
                        shl eax,3
                        mov ecx,[esi+eax].POINT.y
                        sub dword ptr [esp],ecx      ; [esp]=(y-polyY)
                        mov eax,i
                        shl eax,3
                        mov ecx,[esi+eax].POINT.x
                        add dword ptr [esp],ecx
                     pop eax
                     xor edx,edx
                     div dword ptr[esp]
                  pop ecx
                  mov ecx,x
                  cmp eax,ecx
                  jnl pol_i
                     not oddNodes
      pol_i:
   push i
   pop j
   inc i
   mov eax,nPointCounts
   cmp i,eax
   jl loop_i
   
   mov eax,oddNodes
   
   ret
IsInsidePolygon endp
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

UtillMasm

oh my fo!
this man looks like a terrorist!

dedndave

#14
lol - that man is Farabi   :eek
give me some time to look at the code......

that is some monster code - lol
for the polygon, you have a set of lines - a list ? with end-points ?