Ansys Learning Forum › Forums › Discuss Simulation › Photonics › Trapezoidal ring › Reply To: Trapezoidal ring
October 30, 2024 at 1:10 am
Kirill
Ansys Employee
Hello Rahul,
You’ll need to adjust your px
and py
coordinates. Check this example:
# Parameters start_angle = 0.0; # Start angle in degrees end_angle = 45.0; # End angle in degrees radius = 10.0; # Radius of the arc m = 0.55191502449; # "Magic number" for a 90° arc approximation # Convert angles to radians start_angle_rad = start_angle * pi / 180; end_angle_rad = end_angle * pi / 180; # Calculate arc angle arc_angle = end_angle_rad - start_angle_rad; # Adjust the "magic number" for the specified arc angle m_adj = m * arc_angle / (pi / 2); # Calculate control points for Bezier curve approximation # Starting point (p0) p0_x = cos(start_angle_rad) * radius; p0_y = sin(start_angle_rad) * radius; # First control point (p1) p1_x = p0_x - sin(start_angle_rad) * m_adj * radius; p1_y = p0_y + cos(start_angle_rad) * m_adj * radius; # Ending point (p3) p3_x = cos(end_angle_rad) * radius; p3_y = sin(end_angle_rad) * radius; # Second control point (p2) p2_x = p3_x + sin(end_angle_rad) * m_adj * radius; p2_y = p3_y - cos(end_angle_rad) * m_adj * radius; # Create array of control points px = [p0_x; p1_x; p2_x; p3_x]; py = [p0_y; p1_y; p2_y; p3_y]; p = [px, py]; # Output ?("Control points:"); ?num2str(p, "%.3f");
So for:
px = [10.000; 10.000; 9.022; 7.071]; py = [ 0.000; 2.760; 5.120; 7.071];
you should get an approximation of a 45° arc.
I also suggest reviewing the following resources:
- Approximation of a cubic Bézier curve by circular arcs and vice versa – This provides a solid mathematical discussion on the topic.
- Approximate a circle with cubic Bézier curves – This source presents a clear discussion on approximation accuracy.
- Bézier curves - Desmos calculator – A nice interactive tool to speed up your understanding of Bézier curves.
I hope you find this helpful.
Best regards,
Kirill