LWPOLYLINE creating arcs from vertices / edges

I’m using POLYLINE for my dxf export all is good except I can’t smoothen the arc’s it always returns as straight edges(lines). Then I stumbled upon LWPOLYLINE. The arcs are smooth but I don’t know how do I correctly generate an arc. I ran into 2 major issues

  1. I separated the Curve line but the figure is still closing (notice the straight line)
  2. I don’t know where I could get the value I could use for the bulge and where do I put it

In the example,what I did is I extract the first and last vertex of the arc then add the bulge on the last vertex (used the end_angle). The white one is the one that I generated

sample.dxf (1.1 KB)

You statements and questions are assuming we understand things that are not explained.

Are you writing a DXF exporter, are you using a 3rd party DXF library, or are you calling the native SketchUp export API method ?

You show a screen shot, but it has several curve objects within it. It would be nice if you zoomed in closer and selected the curve you are speaking of in the image.

FTR, SketchUp is a surface modeler, and all curves and circles are represented internally with a series of segmented edges.

Lastly, it would help if you show a snippet of the problem code.
(Please read how to post code in the forum.)

I think you will find the best info about the DXF format in the Autodesk documentation, for instance

1 Like

Basically Im writing a dxf exporter and I can’t get the arc part done so I’m trying to seek an advice on how to draw an arc from an Sketchup::Edge or Sketchup::ArcCurve object. Right now I’m using a LWPOLYLINE command on the dxf part. It is written like this:

SECTION
  2
ENTITIES
  0
LWPOLYLINE
 8
layer_1
 70
 0
 39
10.0
 90
 24
 43
 1
 75
 8
 10
 0.0
 20
 66.91786120745175
 30
 0
 91
 41322
 10
 0.0
 20
 0.3937007874015748
 30
 0
 91
 41322
 10
 0.0
 20
 0.3937007874015748
 30
 0
 91
 41254
 10
 17.529615927097424
 20
 0.3937007874015748
 30
 0
 91
 41254
 10
 29.034901335728925
 20
 11.5052854086315
 30
 0
 42
 0.0
 10
 17.529615927097424
 20
 0.3937007874015748
 30
 0
 42
 1.5707963267948966
 10
 29.034901335728925
 20
 11.5052854086315
 30
 0
 91
 41310
 10
 29.034901335728925
 20
 82.1751799469988
 30
 0
 91
 41310
 10
 29.034901335728925
 20
 82.1751799469988
 30
 0
 91
 41258
 10
 23.43725337550044
 20
 82.1751799469988
 30
 0
 91
 41258
 10
 23.43725337550044
 20
 82.1751799469988
 30
 0
 91
 41321
 10
 23.43725337550044
 20
 66.91786120745175
 30
 0
 91
 41321
 10
 23.43725337550044
 20
 66.91786120745175
 30
 0
 91
 41314
 10
 0.0
 20
 66.91786120745175
 30
 0
 91
 41314
 0
ENDSEC
 0
EOF

but the problem here is I don’t exactly know what to put on the 43 (Bulge prop) or where to extract it from the mentioned

arc

Thanks for the info I was actually using that but I’m not sure on how to build an arc using LWPOLYLINE / POLYLINE object because from sketchup I’m only getting the edges which are not really curve

The SketchUp Ruby API does have “virtual” curve objects.
If you have a reference to any of it’s edges, then you get the curve reference via …

curve = edge.curve

… or if you have an array of the edges …

curve = edges.first.curve

Then you can get the curve properties:

start_pt = curve.first_edge.start.position
end_pt   = curve.last_edge.end.position
if curve.is_a?(Sketchup::ArcCurve)
  center = curve.center
  radius = curve.radius
  start_angle = curve.start_angle
  end_angle = curve.end_angle
  plane = curve.plane
  normal_vector = curve.normal
end

Refer to docs (FYI, in Ruby subclasses inherit methods from their ancestors):

According to the DXF spec, the bulge is not code 43 (which is constant width.)
I’d think you’d need to use a combination of 41 and 42. (See pp 102…103)

DXF spec, page 251, establishes that the LWPOLYLINE is a 2D entity, and it’s vertices are 2D, expressed within the OCS (the entity’s local coordinate system.) So you’ll need to know how to determine the world coordinates of the SketchUp entity and transform that into the DXF entity’s OCS. (pp 251…252)

If the SketchUp curve is not within a group or component instance, then the coordinates of the points will be in model coordinates. If they are grouped or in a component, then you’ll need to multiply the instance transformations of the nestings, to convert to “world” coordinates.

1 Like

Thanks for the info I manage to generate a near replicate of the shape that I want. Using the ArcCurve I filtered out the vertices and just add a bulge on the vertex before the arc now it looks like thisarc buldge

Do you think is there a way that I could set or even derive the bulge value (42) from the ArcCurve object?

There is, but it requires some math. The bulge value is called the sagitta.

Thanks here’s a snippet of the code using the formula but I think I missed something.

  def calculate_sagita(curve)
   vertices = curve.vertices.values_at(0, -1)
   r = curve.radius
   l = vertices.first.position.distance(vertices.last.position).to_f / 2
   s = r - (Math.sqrt((r**2) - (l**2 )))
   return s
  end

Hmm…I tried your code on a sample I drew using the SketchUp arc tool, and it returned the correct value. Can you share the model for which you got an incorrect value? I know nothing about LWPOLYLINE, but I can try to help with SketchUp :wink:

iregular_shape.skp (1.1 MB)

Here’s my model. Basically what I did is create a rectangle then circle on the lower right then delete the outer side of the circle and push/pull it.

I think its also worth mentioning how do I know if the bulge is positive or negative. In this case I think it should be negative but from the formula I’m getting a positive

I think the question you are asking is addressed on this page:


The curvature of a Polyline Arc segment is defined using a quantity known as bulge. This unit measures the deviation of the curve from the straight line (chord) joining the two vertices of the segment. It is defined as the ratio of the arc sagitta (versine) to half the length of the chord between the two vertices; this ratio is equal to the tangent of a quarter of the included arc angle between the two polyline vertices.

In this way, a negative bulge indicates that the arc follows a clockwise direction from the first vertex to the next, with a positive bulge describing an anticlockwise oriented arc. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.

An AutoCAD Arc Entity is defined by a center, radius and start & end angle. The arc is always defined to be anticlockwise oriented, that is, following an anticlockwise direction from the start angle to the end angle.

1 Like

Thanks I finally figure it out. It turns out that I have to divide the sagita by the half of the length of the cord to get the bulge correctly

1 Like