Polygon Operations Extension

Home Forums Problems and solutions in GDL GDL add-ons Polygon Operations Extension

Viewing 7 reply threads
  • Author
    Posts
    • #2025
      Heimo Mooslechner
      Participant

      there is : https://gdl.graphisoft.com/gdl-docs/gdl-guide/chapter-12-miscellaneous/polygon-operations-extension/ her in this Site.

      I would like to have some examples to look at – not just this documentation here – to shorten my learningcurve and to see the possibilities about it. I want to see, if it is possible tu use it for scripting without beeng a mathematal genius -smile..

      Teacher in HTL-Salzburg
      AC5-19, Win and Mac
      GDL hobby developer

    • #2032
      Heimo Mooslechner
      Participant

      What i am looking for exactly is this:

      I have a given Array of x and y – a closed polygone in the form of:

      x[points] and y[points] and the number of points in the Array in an extra integer named “points”.

      I want to get a second polygone – with an inner offset to the original one.

      As far as i understand the GDL-handbook, i first have to open a channel with the code:

      kanal = INITADDONSCOPE ("PolyOperations ", "", "")

      Then i have to prepare my source and Target – Polygones:

      
      ! --- QUELL- + ZIELCONTAINER ERZEUGEN
      PREPAREFUNCTION kanal, "CreateContainer", "Eingang", ""
      PREPAREFUNCTION kanal, "SetSourceContainer", "Eingang", ""
      
      PREPAREFUNCTION kanal, "CreateContainer", "Ergebnis", ""
      PREPAREFUNCTION kanal, "SetDestinationContainer", "Ergebnis", ""
      

      after this, i have to give my extra stored coordinates into one array:

      
      for oft = 1 to points
      
      arrayname[oft][1] = x[oft]
      arrayname[oft][2] = y[oft]
      arrayname[oft][3] = 0 !! angle?
      nZug=nZug+1 : zug[nZug]=oft
      
      next oft
      

      Then i have to give the array to the function:

      PREPAREFUNCTION kanal, "Store", "Polygon", points, 1, arrayname, zug (contourArray)

      i have difficulties to understand this:

      contourArray: An array which contains the index of the last vertex of the i-th contour. It must have exactly nContours items.

      Therefor i would need an Example how to to this correctly!

      Then i have to “init” the calculation with: ?? or how exactly?

      dim resPolyIDArray[]
      nPgon = CALLFUNCTION (Kanal, "OffsetEdge", "Polygon", resPolyIDArray)

      Then i have to read out the resulting array:

      nPgon = CALLFUNCTION (Kanal, "GetDestinationPolygons", "", resPolyIDArray)

      after this i can close it:

      CLOSEADDONSCOPE (Kanal)

      Then i can use put and get for an Poly2-Command to draw the polygone. Im i Right so far? There are a lot of possible mistakes i can make with this very complex command…

      Teacher in HTL-Salzburg
      AC5-19, Win and Mac
      GDL hobby developer

    • #2033
      Heimo Mooslechner
      Participant

      I really would like to get an working GDL with only the functionality of the inner offset for a polygone!

      Teacher in HTL-Salzburg
      AC5-19, Win and Mac
      GDL hobby developer

    • #2034
      Gergely Fehér
      Keymaster

      There are examples for the add-on in the Library Developer toolkit, and you can check the “Sill” and “Board” macros in the standard library for examples of using the addon. They are not about the offset function, but they shows how to use the contour array.

      Gergely Fehér
      Team Leader, Library Team
      GRAPHISOFT SE

    • #2059
      Heimo Mooslechner
      Participant

      I opend the “Sill”-macro and tried to reverse-engeneer it but – real – “i am lost” with this.

      It was much easier for me to write my own code for it to calculate the intersectionpoints:

      “Innenversatz der Kontur”:

      breite = -UEBERDAEMMUNGSBREITE

      for k = 1 to points

      !! Zuweisungen zu Segment
      if k = 1 then !! 1. Segment – ergibt auch letzten Punkt
      Winkelzuvor = alpha2D[points]
      Winkeljetzt = alpha2D[k]
      Winkeldanach = alpha2D[k+1]

      x1=x[points-1] !!!Koordinaten im Segment rauspicken
      x2=x[k]

      y1=y[points-1]
      y2=y[k]

      x11=x[k] !!!Koordinaten im Segment rauspicken
      x21=x[k+1]

      y11=y[k]
      y21=y[k+1]

      gosub “Parallele1”
      gosub “Parallele2”
      gosub “Schnittpunkte1”
      gosub “Schnittpunkt zweier Linien – 2D”

      ! addx xp[k]
      ! addy yp[k]
      ! circle 0.01
      ! del 2

      endif

      if k # points and k#1 then !! zwischen- Segmente
      Winkelzuvor = alpha2D[k-1]
      Winkeljetzt = alpha2D[k]
      Winkeldanach = alpha2D[1]

      x1=x[k-1] !!!Koordinaten im Segment rauspicken
      x2=x[k]

      y1=y[k-1]
      y2=y[k]

      x11=x[k] !!!Koordinaten im Segment rauspicken
      x21=x[k+1]

      y11=y[k]
      y21=y[k+1]

      gosub “Parallele1”
      gosub “Parallele2”
      gosub “Schnittpunkte1”
      gosub “Schnittpunkt zweier Linien – 2D”

      ! addx xp[k]
      ! addy yp[k]
      ! circle 0.01
      ! del 2

      endif
      !! Ende zu Segment

      next k

      !
      !for k= 1 to points-1
      !
      ! put xp[k]
      ! put yp[k]
      !
      !next k
      !
      !
      !
      !PRISM nsp/2, 0.01, !! Dummy-Prism für den späteren Wallniche-Befehl
      !get(nsp)
      !

      return !!! Ende “Innenversatz der Kontur”

      “Parallele1”:

      dx = x2 – x1 !!!x+y Distanz der Punkte des Segmentes
      dy = y2 – y1

      if dx < 0 then dx = -dx
      if abs(dx) < eps then dx=eps

      if dx < eps and dx < -eps then
      Winkelsegment = 90
      else
      WinkelSegment = atn(dy/dx)
      endif

      RewinSeg = WinkelSegment – 90

      Diagonale1 = sqr (dx^2+dy^2) !!!!Distanz der Punkte des Segmentes

      P1x1 = -breite * cos(RewinSeg)+x1
      P1y1 = -breite * sin(RewinSeg)+y1
      p1x2 = -breite * cos(RewinSeg)+x2
      p1y2 = -breite * sin(RewinSeg)+y2

      if x2 < x1 then
      P1y1 = breite * sin(RewinSeg)+y1
      p1y2 = breite * sin(RewinSeg)+y2
      else
      endif

      return

      “Parallele2”:

      dx1 = x21 – x11 !!!x+y Distanz der Punkte des Segmentes
      dy1 = y21 – y11

      if dx1 < 0 then dx1 = -dx1
      if abs(dx1) < eps then dx1 = eps

      if dx1 < eps and dx1 < -eps then
      Winkelsegment1 = 90
      else
      WinkelSegment1 = atn(dy1/dx1)
      endif

      RewinSeg1 = WinkelSegment1 – 90

      Diagonale2 = sqr (dx1^2+dy1^2) !!!!Distanz der Punkte des Segmentes

      P2x1 = -breite * cos(RewinSeg1)+x11
      P2y1 = -breite * sin(RewinSeg1)+y11
      p2x2 = -breite * cos(RewinSeg1)+x21
      p2y2 = -breite * sin(RewinSeg1)+y21

      if x21 < x11 then
      P2y1 = breite * sin(RewinSeg1)+y11
      p2y2 = breite * sin(RewinSeg1)+y21
      else
      endif

      return

      “Schnittpunkte1”: !!!!Nicht von mir erfunden!

      getValues = 1
      put p1x1, p1y1, p1x2, p1y2, p2x1, p2y1, p2x2, p2y2
      gosub “Schnittpunkt zweier Linien – 2D”
      if not(parallelLines~5) then

      spx = x~5
      spy = y~5

      xp[k] = spx
      yp[k] = spy

      else

      endif

      return

      “Schnittpunkt zweier Linien – 2D”: !!!!Nicht von mir erfunden!

      if getValues then
      x11~5 = get(1): y11~5 = get(1)
      x12~5 = get(1): y12~5 = get(1)
      x21~5 = get(1): y21~5 = get(1)
      x22~5 = get(1): y22~5 = get(1)
      getValues = 0
      endif
      u1x~5 = x12~5 – x11~5
      u1y~5 = y12~5 – y11~5
      u2x~5 = x22~5 – x21~5
      u2y~5 = y22~5 – y21~5
      !Prüfung ob parallel und Punkt finden
      D~5 = u2x~5*u1y~5 – u1x~5*u2y~5
      if abs(D~5) < eps then
      parallelLines~5 = 1
      else
      parallelLines~5 = 0
      endif

      !Schnittpunkt von nicht parallelen Linien:
      if not(parallelLines~5) then
      t~5 = (u1x~5*(y21~5 – y11~5) – u1y~5*(x21~5 – x11~5))/D~5
      x~5 = x21~5 + t~5*u2x~5
      y~5 = y21~5 + t~5*u2y~5
      else

      xp[k] = P2x1!p1x2 !!!!!!!!!!!!nur die halbe Wahrheit – nur für genau waagrechte und senkrechte Polygone möglich!!!
      yp[k] = P2y1!p2y2 !!! falls parallele waagrechte, dann nimm die Y und Y der vorigen Punkte
      !!!!!! für iregndwelchen anders geneigten Parallelen muß es noch gerechnet werden!!

      endif

      return

      
      
      If someone needs it - feel free to use it. The central part is not from me - ist an internet-advice from a friend i dont know where he got it: So i cant tell about licence of this Code..
      
      

      “Schnittpunkt zweier Linien – 2D”: !!!!Nicht von mir erfunden!

      if getValues then
      x11~5 = get(1): y11~5 = get(1)
      x12~5 = get(1): y12~5 = get(1)
      x21~5 = get(1): y21~5 = get(1)
      x22~5 = get(1): y22~5 = get(1)
      getValues = 0
      endif
      u1x~5 = x12~5 – x11~5
      u1y~5 = y12~5 – y11~5
      u2x~5 = x22~5 – x21~5
      u2y~5 = y22~5 – y21~5
      !Prüfung ob parallel und Punkt finden
      D~5 = u2x~5*u1y~5 – u1x~5*u2y~5
      if abs(D~5) < eps then
      parallelLines~5 = 1
      else
      parallelLines~5 = 0
      endif

      !Schnittpunkt von nicht parallelen Linien:
      if not(parallelLines~5) then
      t~5 = (u1x~5*(y21~5 – y11~5) – u1y~5*(x21~5 – x11~5))/D~5
      x~5 = x21~5 + t~5*u2x~5
      y~5 = y21~5 + t~5*u2y~5
      else

      xp[k] = P2x1!p1x2 !!!!!!!!!!!!nur die halbe Wahrheit – nur für genau waagrechte und senkrechte Polygone möglich!!!
      yp[k] = P2y1!p2y2 !!! falls parallele waagrechte, dann nimm die Y und Y der vorigen Punkte
      !!!!!! für iregndwelchen anders geneigten Parallelen muß es noch gerechnet werden!!

      endif

      `

      Teacher in HTL-Salzburg
      AC5-19, Win and Mac
      GDL hobby developer

    • #2060
      Heimo Mooslechner
      Participant

      Sorry about the formating-i made a mistake, but after three times of editing, ist not possible any more to change anything here.

      Teacher in HTL-Salzburg
      AC5-19, Win and Mac
      GDL hobby developer

    • #2290
      Pertti Pääsky
      Participant

      Hi Heimo
      Here’s an object which opened the POE door for me, it is originally made by GS, I have only issued the offset-lines script.
      As you know it is hard to understand how POE works.
      Basicly you define the polygons, add information of contours and edges. Then you open the add on and perform operations. What you get is almost similar data as you put in. Of course it must be processed to get resulting polygons.
      I think there was a bug in the script so that it works not in all situations, but maybe this helps a little.

      AC 19 Win 7 HP elitebook

    • #2291
      Pertti Pääsky
      Participant

      “Upload Errors:
      1.PolyOperations_Example19.gsm: Sorry, this file type is not permitted for security reasons” !!!

      Maybe .zip is more safe?

      AC 19 Win 7 HP elitebook

Viewing 7 reply threads
  • The forum ‘GDL add-ons’ is closed to new topics and replies.