Article | 70002254 |
Type | HowTo |
Product | WebJS |
Version | 9 |
Date Added | 8/18/2022 12:00:00 AM |
Fixed | 10.1002.0.2 (8/18/2022 12:00:00 AM) |
Submitted by | Brendan Fry |
Summary
How to merge polygons or make other combinations
Solution
example of polygon clip between regions.
//create 2 rectangle polylines var pl1 = vdcanvas.AddPolyline([[0, 0, 0], [2, 0, 0], [2, 2, 0], [0, 2, 0], [0, 0, 0]], false, {}); var pl2 = vdcanvas.AddPolyline([[1, 1, 0], [3, 1, 0], [3, 3, 0], [1, 3, 0], [1, 1, 0]], false, {}); //get the sample points of each polyline var pts1 = vdcanvas.GetEntitySamplePoints(pl1); var pts2 = vdcanvas.GetEntitySamplePoints(pl2); //Calculate an array of regions that represent the clipping result of passed ptsarray regions according to the passed opers var regions = gpc.clip_oper([pts1, pts2], [gpc.OPER_UNION, gpc.OPER_UNION]);//the union of both polygons //var regions = gpc.clip_oper([pts1, pts2], [gpc.OPER_INT, gpc.OPER_INT]);//the intersection //var regions = gpc.clip_oper([pts1, pts2], [gpc.OPER_DIFF, gpc.OPER_DIFF]);//the difference of the first minus the second //create a hatch to display the result var hatch = vdcanvas.AddPolyHatch(regions, regions); hatch.HatchProperties = vdcanvas.createNewHatchProperties('solid', null, vdConst.colorFromString("255,0,0,90"), 1.0, 0.0); //redraw the scene setTimeout(vdcanvas.redraw);