Length of an arc between two angles: Difference between revisions

Added Easylang
(J draft)
(Added Easylang)
 
(10 intermediate revisions by 4 users not shown)
Line 141:
end arc_length_both;
</syntaxhighlight>
 
=={{header|ALGOL 68}}==
{{Trans|ALGOL W}}
<syntaxhighlight lang="algol68">
BEGIN
# returns the length of the arc between the angles a and b on a circle of radius r #
# the angles should be specified in degrees #
PROC major arc length = ( REAL a, b, r )REAL:
BEGIN
REAL angle := ABS ( a - b );
WHILE angle > 360 DO angle -:= 360 OD;
IF angle < 180 THEN angle := 360 - angle FI;
( r * angle * pi ) / 180
END # majorArcLength # ;
# task test case #
print( ( fixed( major arc length( 10, 120, 10 ), -10, 4 ), newline ) )
END
</syntaxhighlight>
{{out}}
<pre>
43.6332
</pre>
 
=={{header|ALGOL W}}==
Line 169 ⟶ 191:
<pre> 10 arc 10 120
43.6332313</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">degToRad: function [deg]-> deg * pi // 180
doublePi: 2 * pi
 
arcLength: function [r, a, b][
d: (abs a-b) % doublePi
return r * (d >= pi)? -> d -> doublePi - d
]
 
print ["Arc length:" to :string .format:".5f" arcLength 10 degToRad 10.0 degToRad 120.0]</syntaxhighlight>
 
{{out}}
 
<pre>Arc length: 43.63323</pre>
 
=={{header|AutoHotkey}}==
Line 288 ⟶ 326:
<pre>
43.6332313
</pre>
 
=={{header|EasyLang}}==
{{trans|Python}}
<syntaxhighlight>
func arc_length r angleA angleB .
return (360 - abs (angleB - angleA)) * pi * r / 180
.
print arc_length 10 10 120
</syntaxhighlight>
{{out}}
<pre>
43.63
</pre>
 
Line 696 ⟶ 747:
Length of an arc between two angles:
43.6332313
</pre>
 
=={{header|RPL}}==
The function also works when the difference between the two angles is greater than 180 degrees.
≪ DEG - ABS 360 OVER - MAX
* 180 / π * →NUM
≫ '<span style="color:blue">MAJARC</span>' STO
 
10 10 120 <span style="color:blue">MAJARC</span>
10 10 350 <span style="color:blue">MAJARC</span>
{{out}}
<pre>
2: 43.6332312999
1: 59.3411945678
</pre>
 
Line 723 ⟶ 788:
=={{header|Wren}}==
{{trans|Julia}}
<syntaxhighlight lang="ecmascriptwren">var arcLength = Fn.new { |r, angle1, angle2| (360 - (angle2 - angle1).abs) * Num.pi / 180 * r }
 
System.print(arcLength.call(10, 10, 120))</syntaxhighlight>
2,013

edits