Yep, that is the sagitta of an arc.
The math is simple:
The ideal arc length given the maximum tolerance epsilon:
idealArcLength = 2 * acos(1.0 - (epsilon / radius))
But that may chop your arc up in N equal pieces plus the remaining as a shorter segment.
Chopping the arc in N (rounded up) equal pieces is then:
segmentCount = ceil(arcAngleLength / idealArcLength)
And there is a catch … As always … epsilon / radius can be more than 2.00
In that case the acos() will be invalid because it is less than -1.00.
‘epsilon’ and ‘radius’ are lengths and thus always positive, the acos() can not exceed 1.00
The next limit situation is segmentCount = 1 … Short arc or small radii.
You might set a minimum segmentCount to at least mimic the curved nature.
In arcEntity.setLayerId(this.arcLayer.getId()); you refer to this.arcLayer that you added to an operation.
That operation is not yet applied and the object id will still be invalid.
You must first apply the layer op and retrieve the layer back from the document to know its id …
Also, I’ve found how to change the color of an object without using layer params, so I’ve used that instead, it’s better and doesn’t crash by nature lol
The arc with radius 1000 units chopped in 9 may be a good representation when it is short.
But when it is let’s say 180 degrees then the line segments are about 347.3 units long and the deviation with the original arc or discretization tolerance is about 15.2 units.