Point in polygon

Started by Nicola, April 07, 2022, 04:53:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Charles Pegge

Yes, there is progress, though this 2d vector stuff is surprisingly tricky. I am mor accustomed to 3d graphics :)

Charles Pegge

This is the code for InsideOoutsidePoints, your original quest. It should still work with the original Geoplanar.inc.


  % Title "Intersections Demo"
'% Animated
'% ScaleUp
'% PlaceCentral
'% AnchorCentral
  uses consoleG
  uses GLO2\GeoPlanar

  sub boundaries()
  ================
  indexbase 0

  string tab="    "
  point  p
  int    a,i,j,k

  seed=0x123567

  line  d[8]
  float f[16]
  f={-1,-1, 1,-1,  1,1, -1,1}
  for i=0 to 7
    f[i]+=rnd()*0.4 'turbulate
  next
  '
  d[0]={ f[0],f[1],f[2],f[3]}
  d[1]={ f[2],f[3],f[4],f[5]}
  d[2]={ f[4],f[5],f[6],f[7]}
  d[3]={ f[6],f[7],f[0],f[1]}
  '
  for i=0 to 7
    f[i]=f[i]*0.5 'smaller inner form
  next
  '
  d[4]={ f[0],f[1],f[2],f[3]}
  d[5]={ f[2],f[3],f[4],f[5]}
  d[6]={ f[4],f[5],f[6],f[7]}
  d[7]={ f[6],f[7],f[0],f[1]}



  'shading
  flat 'default
  '
  color 0,1,1
  'printl "Inside " tab p.x tab p.y

  scale 10,10

  move 1.5,-1
  '
  color 0,1,1
  thickness 3
  '
  for i=0 to 7
    drawline @d[i]
  next
  '
  int inside
  point pio
  line dd
  '
  float x,y
  for j=1 to 1000
    x=2*rnd
    y=2*rnd
    pio={x,y}
    gosub checkInside
  next
  exit sub
  '
  CheckInside:
  ============
  color 1,1,0
  pointsize 4
  dd={-1000,pio.y,1000,pio.y}
  inside=0
  for i=0 to 7
   a=intersected d[i],dd,p
   if a
     'drawline @dd
     'drawpoint @p
     if p.x<pio.x
       inside=1-inside 'toggle
     endif
   endif
  next
  '
  if inside
    color 1,1,0
  else
    color 0.8,0,0
  endif
  pointsize 4
  drawpoint @pio
  ret 
 



  end sub


  sub main()
  ==========
  string s
  cls 0,0,0
  pushstate
  scale 2,2
  'typeface=1
  printl "Inside / Outside Points"
  popstate
  '
  move 0,-2
  '
  PushState
  move 1,-1
  boundaries()
  PopState
  '
 
  end sub

  EndScript


Nicola

#17
Hi Charles,
did not come out the same result as yours ... :-(

Charles Pegge

#18
.Ok, Sorry about that. Here is my current Geoplanar.inc which belongs in /inc/GLO2

I think it will be quite open-ended for some time.

You can resize ConsoleG apps and take a jpeg-snapshot with Ctrl-P.

Nicola

Hi Charles,
OK now.
I am attaching what I had done which also seems to work quite well, even with the old geoplanar.inc


' % Title "Console Demo"
'% Animated
'% ScaleUp
'% PlaceCentral
'% AnchorCentral
  uses consoleG
  uses console
  uses GLO2\GeoPlanar

  sub drawintersections()
  =======================
  string tab="    "
  line   d1,d2
  point  p
  sys    a
  int n,j,i,k,np,xt
  n=10 'number of poly
  np=9 'number of point to evaluate

'points of poly
float px={41.84076349611504,41.837170604812826,41.83233185912741,41.82782814339409,41.82006567695157,41.81968232089131,41.81450678946148,41.809282912371984,41.81431509508004,41.820880300959615}
float py={12.466150927636479,12.480682808848268,12.48042560741089,12.478946699145974,12.481390112801055,12.468530040932215,12.461135499607634,12.45496266511059,12.44788962558273,12.438437472759132}

'points to prove
float fx={41.834844,41.8300796,41.829849,41.832556,41.8284089,41.828539,41.8320845,41.8393343,41.820684}
float fy={12.471219,12.4668936,12.467641,12.463344,12.4608684,12.471123,12.4649883,12.4637847,12.479901}

for j=1 to np
xt=0 'conta il numero di intersenzioni
for i=1 to n
k=i+1
if i=n then k=1
d1={px[i],py[i],px[k],py[k]}
'd2={41.834844,12.471219,41.834844,0}
d2={fx[j],fy[j],fx[j],0}
a=intersected d1,d2,p
if a then
printl "CROSS" tab j "," i ")" tab a tab p.x tab p.y
xt++
end if
p.x=0
p.y=0
next i
if frac(xt/2)=0 then printl fx[j] "," fy[j] tab "> OUT"
if frac(xt/2)<>0 then printl fx[j] "," fy[j] tab "> IN"
next j
printl

end sub


sub main
=============================
  string s
  printl "Intersection Points"
  DrawIntersections
  pause
  exit
end sub

  EndScript


Theo Gottwald

#20
This stuff reminds me about neural networks where you can train the network to make classification of elements :-).
The advantage is that you do not need to find the formula, because the network will find the formula.
Neural network optimizations would be an interesting topic for oxygen possibly.
Because the basic underlying formulas are simple and can easily be optimzed in ASM.


Neural Networks for Classification

Charles Pegge

Hi Theo,

Delaunay triangles connect points so that no triangle may intersect another triangle. It can be solved by creating all possible lines between the points, then sorting into ascending order of length and testing each for intersections, giving priority to the shorter lines.

This uses random points, but it could be more interesting with other arrangements .

Nicola

Charles,
this topic is interesting. I have to see to deepen it ...
Cheers

Johan Klassen

Good day everyone :)
this is a very deep and interesting subject, you find a lot of info in the web like https://www.cs.cmu.edu/~quake/triangle.html
  •  

Nicola

Hi,
is there anyone who has tried the example I posted, or has tried in some way what is described?



Quote from: Nicola_Piano on May 13, 2022, 03:52:21 PM
....
I am attaching what I had done which also seems to work quite well, even with the old geoplanar.inc

...
...