Graphisoft®

Basic Library Version: 16

Polygon Operations Macro

  1. General Description
  2. Parameters
  3. Usage

1. General Description

The Polygon operations macro provides functions to assist in working with polygons.

2. Parameters

Name Type Default Remarks
opcode Integer 0 Operation Code
1
Convert ArchiCAD style poligon data to GDL style polygon data
2
Point inside polygon test
3
Line-line intersection
4
Segment-segment intersection
5
Intersect polygons
6
Calculate polygon area
7
Reverse polygon
opmethod Integer 0 Operation Method
edgeAttribute Integer 1 Polygon Edge Attribute
srcPoint Integer 0 Source of Point
pntX Length 0 Point X
pntY Length 0 Point Y
srcLine1 Integer 0 Source of Line 1
line1X1 Length 0 Line1 X1
line1Y1 Length 0 Line1 Y1
line1X2 Length 0 Line1 X2
line1Y2 Length 0 Line1 Y2
srcLine2 Integer 0 Source of Line 2
line2X1 Length 0 Line2 X1
line2Y1 Length 0 Line2 Y1
line2X2 Length 0 Line2 X2
line2Y2 Length 0 Line2 Y2
srcPolygon1 Integer 0 Source of Polygon 1
polygon1 Length Polygon 1
srcPolygon2 Integer 0 Source of Polygon 2
polygon2 Length Polygon 2
result Integer 0 Result Target

3. Usage

1 - Convert ArchiCAD style poligon data to GDL style polygon data

This operation converts an ArchiCAD style polygon (e.g. it can come from AC_WallContourPolygon) to GDL style polygon (it can be passed to any GDL stement, e.g. POLY2_)

Parameter name Remarks
Input parameters  
srcPolygon1 input source of polygon 1
1
Input from the polygon1 parameter
2
Input from the GDL stack
polygon1 The input polygon
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
Output parameters  
arrayParam The converted polygon (X1, Y1, status1... Xn, Yn, statusn)

Example code - input from parameters, return values on GDL stack:

call "PolygonOperations", parameters opcode = 1, srcPolygon1 = 1, ! input from a parameter polygon1 = AC_WallContourPolygon, result = 2 ! output to GDL stack poly2_B nsp/3, 1+2+4, 7, 0, get(nsp)

Example code - input from GDL stack, return values in parameter:

for i=1 to vardim1(AC_WallContourPolygon) put AC_WallContourPolygon[i][1], AC_WallContourPolygon[i][2], AC_WallContourPolygon[i][3] next i dim myArrayParam[][3] call "PolygonOperations", parameters opcode = 1, srcPolygon1 = 2, ! input from GDL stack result = 1, ! output to a parameter returned_parameter myArrayParam for i=1 to vardim1(myArrayParam) put myArrayParam[i][1], myArrayParam[i][2], myArrayParam[i][3] next i poly2_B nsp/3, 1+2+4, 7, 0, get(nsp)

2 - Point inside polygon test

This operation returns whether the point is inside the given polygon or not.

Parameter name Remarks
Input parameters  
srcPolygon1 input source of polygon 1
0
No input
1
Input from the polygon1 parameter
2
Input from the GDL stack
polygon1 The input polygon
srcPolygon2 input source of polygon 2
0
No input
1
Input from the polygon2 parameter
2
Input from the GDL stack
polygon2 The input polygon
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
pntX point X
pntY point Y
Output parameters  
ret Returned status value with returned_parameter or through the GDL stack, depending on the result parameter.
0
Operation error
1
Point inside the polygon
2
Point outside the polygon
3
Point on the edge of the polygon
4
Point on a vertex of the polygon

Remarks:

  1. The polygon can be convex or concave
  2. It works with polygons containing straight segments only
  3. The polygon must not contain holes
  4. The input polygon from polygon1 or from polygon2 must be closed
  5. The input polygon from GDL stack can be opened (it is closed automatically)

call "PolygonOperations", parameters opcode = 2, srcPolygon1 = 1, polygon1 = AC_WallContourPolygon, result = 2, pntX = pntX, pntY = pntY res = get(1) add2 pntX, pntY if res = 1 then ! Inside circle2 0,0, 0.1 endif if res = 2 then ! Outside endif if res = 3 then ! On Edge rect2 -0.01,-0.01, 0.01,0.01 endif if res = 4 then ! On Vertex circle2 0,0, 0.1 rect2 -0.01,-0.01, 0.01,0.01 endif del 1

3 - Line-line intersection

This operation determines the intersection point of two 2D lines.

Parameter name Remarks
Input parameters  
srcLine1 input source of line 1
1
Input from the line1X1, line1Y1, line1X2, line1Y2 parameters
2
Input from the GDL stack
line1X1, line1Y1, line1X2, line1Y2 The line 1
srcLine2 input source of line 2
1
Input from the line2X1, line2Y1, line2X2, line2Y2 parameters
2
Input from the GDL stack
line2X1, line2Y1, line2X2, line2Y2 The line 2
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
Output parameters  
ret Returned status value with returned_parameter or through the GDL stack, depending on the result parameter.
0
no intersection, parallel lines
1
the lines intersect
cx,cy Returned intersection point with returned_parameter or through the GDL stack, depending on the result parameter.

line2 x1,y1, x2,y2 line2 x3,y3, x4,y4 put x1,y1, x2,y2, x3,y3, x4,y4 call "PolygonOperations", parameters opcode = 3, srcLine1 = 2, srcLine2 = 2, result = 2 state = get(1) cx = get(1) cy = get(1) if state > 0 then circle2 cx, cy, 0.1

4 - Segment-segment intersection

Same as the line-line intersection, but with finite line segments

Parameter name Remarks
Input parameters  
Same as the line-line intersection
Output parameters  
ret Returned status value with returned_parameter or through the GDL stack, depending on the result parameter.
-1
no intersection, but segments are not parallel
0
no intersection, parallel lines
1
intersection point lies on S1 segment, but not on S2
2
intersection point lies on S2 segment, but not on S1
3
intersection point is inside of both segments
cx,cy Returned intersection point with returned_parameter or through the GDL stack, depending on the result parameter.

line2 x1,y1, x2,y2 line2 x3,y3, x4,y4 call "PolygonOperations", parameters opcode = 4, srcLine1 = 1, line1X1 = x1, line1Y1 = y1, line1X2 = x2, line1Y2 = y2, srcLine2 = 1, line2X1 = x3, line2Y1 = y3, line2X2 = x4, line2Y2 = y4, result = 1, returned_parameters state, cx,cy if state > 0 then circle2 cx, cy, 0.1 if state = 3 then circle2 cx, cy, 0.2

5 - Intersect polygons

This operation intersects two polygons. The caller has the opportunity to contol the result polygon's edge status. It's also possible to receive the intersection points only.

Parameter name Remarks
Input parameters  
opmethod Contour status handling methods
0
edges with original status
1
set status 0 (invisible) for all edges
2
set status 1 (visible) for all edges
3
edges from polygon1 with 1, edges from polygon2 with 0 status
4
edges from polygon1 with 0, edges from polygon2 with 1 status
5
intersection point list
edgeAttribute The edge status of the result polygon (e.g.: 1 for 2D GDL stements and 15 for 3D GDL stements).
srcPolygon1 input source of polygon 1
1
Input from the polygon1 parameter
2
Input from the GDL stack
polygon1 The input polygon
srcPolygon2 input source of polygon 2
1
Input from the polygon2 parameter
2
Input from the GDL stack
polygon2 The input polygon
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
Output parameters  
arrayParam The intersected polygon (X1, Y1, status1... Xn, Yn, statusn)

put -0.5, 0, 0, -0.5, 1, 0, 0.5, 1, 0, 0.5, 0, 0 call "PolygonOperations", parameters opcode = 5, opmethod = 4, edgeAttribute = 1, srcPolygon1 = 1, polygon1 = AC_WallContourPolygon, srcPolygon2 = 2, result = 2 poly2_b nsp/3, 1 + 2 + 4, gs_wallhole_pen_fg, gs_wallhole_pen_bg, get(nsp)

6 - Calculate polygon area

Calculate area of a polygon.

Parameter name Remarks
Input parameters  
srcPolygon1 input source of polygon 1
0
No input
1
Input from the polygon1 parameter
2
Input from the GDL stack
polygon1 The input polygon
srcPolygon2 input source of polygon 2
0
No input
1
Input from the polygon2 parameter
2
Input from the GDL stack
polygon2 The input polygon
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
Output parameters  
area The area of the polygon

Remarks

  1. The input polygon must be closed

7 - Reverse polygon

Reverse the order of vertices in a polygon.

Parameter name Remarks
Input parameters  
srcPolygon1 input source of polygon 1
0
No input
1
Input from the polygon1 parameter
2
Input from the GDL stack
polygon1 The input polygon
result output result
1
Output to a parameter (returned_parameter)
2
Ouput to the GDL stack
Output parameters  
arrayParam The reversed polygon (X1, Y1, status1... Xn, Yn, statusn)