Open KhalilSelyan opened 6 months ago
I don't know enough geometry to comment on calculate_lwpolyline_radius(bulge, chord_length)
, so I'll leave that aside.
I think you'll need to change the calculation of arc_length
. A few lines above where you calculate let theta = 4.0 * bulge.atan();
looks correct and that gets you the included angle of the arc, so from there you'd want to find the ratio of that to the entire circle's circumference, 2 * pi
, so I would do:
let theta = 4.0 * bulge.atan(); // this is correct; theta is the included angle
let r = calculate_lwpolyline_radius(bulge, line_length); // <-- this is the part I'm not sure about, so I'll leave it alone
let full_circle_circumference = 2.0 * std::f64::consts::PI * r; // this is the circumference of the full circle (if it wasn't an arc)
let arc_fraction = theta / (2.0 * std::f64::consts::PI); // this is how much of the circle we actually have: theta / 2pi
let arc_length = arc_fraction * full_circle_circumference; // we only have a fraction of the full circle's circumference
Finally, the LWPOLYLINE might be closed, which means there's an additional segment between polyline.vertices[polyline.vertices.len() - 1]
and polyline.vertices[0]
. I think there's a polyline.is_closed
flag or similar that you can check.
I'm not really sure where to ask i did some googling etc but i couldn't find a decent way to get the right calculation, this is my current code for it but if anyone has a better solution please help.
Practically all i'm looking for is a way to calculate the total length of a lw_polyline with segments and arcs
If this is seems correct please let me know 😅