Skip to content

Commit

Permalink
Align arcs with new object model
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhankoral committed Nov 11, 2024
1 parent 294b49a commit 2a2871f
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions speckle_connector_3/src/speckle_objects/geometry/arc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ def self.to_native(state, arc, layer, entities, &_convert_to_native)
plane = arc['plane']
units = arc['units']
origin = Point.to_native(plane['origin']['x'], plane['origin']['y'], plane['origin']['z'], units)
start_point = Point.to_native(arc['startPoint']['x'], arc['startPoint']['y'], arc['startPoint']['z'], units)
end_point = Point.to_native(arc['endPoint']['x'], arc['endPoint']['y'], arc['endPoint']['z'], units)
normal = Vector.to_native(plane['normal']['x'], plane['normal']['y'], plane['normal']['z'], units)
x_axis = Vector.to_native(plane['xdir']['x'], plane['xdir']['y'], plane['xdir']['z'], units)
radius = Geometry.length_to_native(arc['radius'], units)
start_angle = arc['startAngle']
end_angle = arc['endAngle']

# Normalize angles to range 0 to 2π
start_angle %= 2 * Math::PI
end_angle %= 2 * Math::PI
start_vector = Vector.to_native(start_point.x - origin.x, start_point.y - origin.y, start_point.z - origin.z, units)
end_vector = Vector.to_native(end_point.x - origin.x, end_point.y - origin.y, end_point.z - origin.z, units)

# Ensure start angle is less than end angle for proper drawing
if start_angle > end_angle
start_angle = Math.atan2(start_vector.cross(normal).dot(x_axis), start_vector.dot(x_axis))
end_angle = Math.atan2(end_vector.cross(normal).dot(x_axis), end_vector.dot(x_axis))

if end_angle < start_angle
end_angle += 2 * Math::PI
end

Expand Down

0 comments on commit 2a2871f

Please sign in to comment.