Length of an arc between two angles: Difference between revisions

From Rosetta Code
Content added Content deleted
m (julia example)
Line 24: Line 24:


=={{header|Julia}}==
=={{header|Julia}}==
The task seems to be to find the distance along the circumference of the circle which is NOT swept out between the two angles.
I am unsure of the precise meaning of some of the task text, but using the linked Imgur graphic as a guide, we can find the distance
along the circumference of the circle which is NOT swept out between the two angles.
<lang julia>
<lang julia>
arclength(r, angle1, angle2) = (360 - abs(angle2 - angle1)) * π/180 * r

arclength(r, angle1, angle2) = (360 - angle2 + angle1) * π/180 * r

@show arclength(10, 10, 120) # --> arclength(10, 10, 120) = 43.63323129985823
@show arclength(10, 10, 120) # --> arclength(10, 10, 120) = 43.63323129985823
</lang>
</lang>

Revision as of 12:28, 15 March 2020

Task

Calculate the length of the arc (green) between two angles;


https://imgur.com/a/aYgDLxr

It is important in video game programming

implement a method that takes parameters like:

  • xpos of the circle
  • ypos of the circle
  • radius
  • ang1
  • ang2

return green arc_lenght

example method:

arc_lenght (xpos, ypos, radius, ang1, ang2) { return arc_lenght; }

Julia

The task seems to be to find the distance along the circumference of the circle which is NOT swept out between the two angles. <lang julia> arclength(r, angle1, angle2) = (360 - abs(angle2 - angle1)) * π/180 * r @show arclength(10, 10, 120) # --> arclength(10, 10, 120) = 43.63323129985823 </lang>