c# - Calculating bulge factors for Polyline objects in BricsCAD -


according dxf instructions bulge value (group code 42):

bulge (optional; default 0). bulge tangent of 1 fourth included angle arc segment, made negative if arc goes clockwise start point endpoint. bulge of 0 indicates straight segment, , bulge of 1 semicircle.

now, found resource calculating bulges lisp programming. however, in part states:

the curvature of polyline arc segment defined using quantity known bulge. unit measures deviation of curve straight line (chord) joining 2 vertices of segment. defined ratio of arc sagitta (versine) half length of chord between 2 vertices; ratio equal tangent of quarter of included arc angle between 2 polyline vertices.

in way, negative bulge indicates arc follows clockwise direction first vertex next, positive bulge describing anticlockwise oriented arc. bulge of 0 indicates straight segment, , bulge of 1 semicircle.

i writing routine in c# bricscad , trying create polyline object bulges. there:

at moment, how construct vertices. please note taking extents , offsetting extents margin on either side. @ same time stitching in bulge values:

   polyline opolyrect = new polyline();     opolyrect.addvertexat(0,         new point2d(extentsselection3d.minpoint.x - dmarginleft, extentsselection3d.minpoint.y), 0.0, 0.0, 0.0);     opolyrect.addvertexat(1,         new point2d(extentsselection3d.minpoint.x - dmarginleft, extentsselection3d.maxpoint.y), -0.5, 0.0, 0.0);     opolyrect.addvertexat(2,         new point2d(extentsselection3d.minpoint.x, extentsselection3d.maxpoint.y + dmargintop), 0.0, 0.0, 0.0);     opolyrect.addvertexat(3,         new point2d(extentsselection3d.maxpoint.x, extentsselection3d.maxpoint.y + dmargintop), -0.5, 0.0, 0.0);     opolyrect.addvertexat(4,         new point2d(extentsselection3d.maxpoint.x + dmarginright, extentsselection3d.maxpoint.y), 0.0, 0.0, 0.0);     opolyrect.addvertexat(5,         new point2d(extentsselection3d.maxpoint.x + dmarginright, extentsselection3d.minpoint.y), -0.5, 0.0, 0.0);     opolyrect.addvertexat(6,         new point2d(extentsselection3d.maxpoint.x, extentsselection3d.minpoint.y - dmarginbottom), 0.0, 0.0, 0.0);     opolyrect.addvertexat(7,         new point2d(extentsselection3d.minpoint.x, extentsselection3d.minpoint.y - dmarginbottom), -0.5, 0.0, 0.0);     opolyrect.addvertexat(8,         new point2d(extentsselection3d.minpoint.x - dmarginleft, extentsselection3d.minpoint.y), 0.0, 0.0, 0.0); 

in principle working. problem bulge calculation. picked -0.5 out of air not enough.

the polyline object exposes setbulgeat method pass vertex index , bulge factor.

can please advise me on how put have found action have right bulge factors?

thank you.

an excellent answer kindly provided me bricssys:

look here.

i replicate c# code works great:

public static class extensions {         // adds arc (fillet) @ each vertex, if able.         public static void filletall(this polyline pline, double radius)     {         int = pline.closed ? 0 : 1;         (int j = 0; j < pline.numberofvertices - i; j += 1 + pline.filletat(j, radius))         { }     }      // adds arc (fillet) @ specified vertex. returns 1 if operation succeeded, 0 if failed.     public static int filletat(this polyline pline, int index, double radius)     {         int prev = index == 0 && pline.closed ? pline.numberofvertices - 1 : index - 1;          if (pline.getsegmenttype(prev) != _acdb.segmenttype.line ||           pline.getsegmenttype(index) != _acdb.segmenttype.line)             return 0;          linesegment2d seg1 = pline.getlinesegment2dat(prev);         linesegment2d seg2 = pline.getlinesegment2dat(index);          vector2d vec1 = seg1.startpoint - seg1.endpoint;         vector2d vec2 = seg2.endpoint - seg2.startpoint;          double angle = (math.pi - vec1.getangleto(vec2)) / 2.0;         double dist = radius * math.tan(angle);         if (dist > seg1.length || dist > seg2.length)             return 0;          point2d pt1 = seg1.endpoint + vec1.getnormal() * dist;         point2d pt2 = seg2.startpoint + vec2.getnormal() * dist;          double bulge = math.tan(angle / 2.0);         if (clockwise(seg1.startpoint, seg1.endpoint, seg2.endpoint))             bulge = -bulge;          pline.addvertexat(index, pt1, bulge, 0.0, 0.0);         pline.setpointat(index + 1, pt2);          return 1;     }          // evaluates if points clockwise.         private static bool clockwise(point2d p1, point2d p2, point2d p3)     {         return ((p2.x - p1.x) * (p3.y - p1.y) - (p2.y - p1.y) * (p3.x - p1.x)) < 1e-8;     } } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -