Polygon Operations Macro
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 |
| 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
|
| polygon1 | The input polygon |
| result | output result
|
| 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
|
| polygon1 | The input polygon |
| srcPolygon2 |
input source of polygon 2
|
| polygon2 | The input polygon |
| result |
output result
|
| 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.
|
Remarks:
- The polygon can be convex or concave
- It works with polygons containing straight segments only
- The polygon must not contain holes
- The input polygon from polygon1 or from polygon2 must be closed
- 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
|
| line1X1, line1Y1, line1X2, line1Y2 | The line 1 |
| srcLine2 |
input source of line 2
|
| line2X1, line2Y1, line2X2, line2Y2 | The line 2 |
| result |
output result
|
| Output parameters | |
| ret |
Returned status value with returned_parameter or through the GDL stack, depending on the result parameter.
|
| 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.
|
| 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
|
| 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
|
| polygon1 | The input polygon |
| srcPolygon2 |
input source of polygon 2
|
| polygon2 | The input polygon |
| result | output result
|
| 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
|
| polygon1 | The input polygon |
| srcPolygon2 |
input source of polygon 2
|
| polygon2 | The input polygon |
| result |
output result
|
| Output parameters | |
| area | The area of the polygon |
Remarks
- 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
|
| polygon1 | The input polygon |
| result |
output result
|
| Output parameters | |
| arrayParam | The reversed polygon (X1, Y1, status1... Xn, Yn, statusn) |