Length of an arc between two angles: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 12: | Line 12: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F arc_length(r, angleA, angleB) |
||
R (360.0 - abs(angleB - angleA)) * math:pi * r / 180.0 |
R (360.0 - abs(angleB - angleA)) * math:pi * r / 180.0 |
||
print(arc_length(10, 10, 120))</ |
print(arc_length(10, 10, 120))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 25: | Line 25: | ||
{{libheader|Action! Tool Kit}} |
{{libheader|Action! Tool Kit}} |
||
{{libheader|Action! Real Math}} |
{{libheader|Action! Real Math}} |
||
< |
<syntaxhighlight lang="action!">INCLUDE "H6:REALMATH.ACT" |
||
PROC ArcLength(REAL POINTER r,a1,a2,len) |
PROC ArcLength(REAL POINTER r,a1,a2,len) |
||
Line 50: | Line 50: | ||
ArcLength(r,a1,a2,len) |
ArcLength(r,a1,a2,len) |
||
PrintR(len) |
PrintR(len) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Length_of_an_arc_between_two_angles.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Length_of_an_arc_between_two_angles.png Screenshot from Atari 8-bit computer] |
||
Line 58: | Line 58: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ada.Numerics; |
with Ada.Numerics; |
||
Line 89: | Line 89: | ||
Distance_Io.Put (Arc_Length, Exp => 0, Aft => 4); |
Distance_Io.Put (Arc_Length, Exp => 0, Aft => 4); |
||
New_Line; |
New_Line; |
||
end Calculate_Arc_Length;</ |
end Calculate_Arc_Length;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 97: | Line 97: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
Follows the Fortran interpretation of the task and finds the length of the major arc. |
Follows the Fortran interpretation of the task and finds the length of the major arc. |
||
< |
<syntaxhighlight lang="algolw">begin |
||
% returns the length of the arc between the angles a and b on a circle of radius r % |
% 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 % |
% the angles should be specified in degrees % |
||
Line 110: | Line 110: | ||
% task test case % |
% task test case % |
||
write( r_w := 10, r_d := 4, r_format := "A", majorArcLength( 10, 120, 10 ) ) |
write( r_w := 10, r_d := 4, r_format := "A", majorArcLength( 10, 120, 10 ) ) |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 118: | Line 118: | ||
=={{header|APL}}== |
=={{header|APL}}== |
||
{{works with|Dyalog APL}} |
{{works with|Dyalog APL}} |
||
< |
<syntaxhighlight lang="apl">arc ← (○÷180)×⊣×360-(|(-/⊢))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 10 arc 10 120 |
<pre> 10 arc 10 120 |
||
Line 124: | Line 124: | ||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
< |
<syntaxhighlight lang="autohotkey">MsgBox % result := arcLength(10, 10, 120) |
||
return |
return |
||
arcLength(radius, angle1, angle2){ |
arcLength(radius, angle1, angle2){ |
||
return (360 - Abs(angle2-angle1)) * (π := 3.141592653589793) * radius / 180 |
return (360 - Abs(angle2-angle1)) * (π := 3.141592653589793) * radius / 180 |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>43.633231</pre> |
<pre>43.633231</pre> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f LENGTH_OF_AN_ARC_BETWEEN_TWO_ANGLES.AWK |
# syntax: GAWK -f LENGTH_OF_AN_ARC_BETWEEN_TWO_ANGLES.AWK |
||
# converted from PHIX |
# converted from PHIX |
||
Line 145: | Line 145: | ||
} |
} |
||
function abs(x) { if (x >= 0) { return x } else { return -x } } |
function abs(x) { if (x >= 0) { return x } else { return -x } } |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 152: | Line 152: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
< |
<syntaxhighlight lang="basic">10 DATA 10, 10, 120 |
||
20 READ R, A1, A2 |
20 READ R, A1, A2 |
||
30 GOSUB 100 |
30 GOSUB 100 |
||
Line 159: | Line 159: | ||
100 REM Calculate length of arc of radius R, angles A1 and A2 |
100 REM Calculate length of arc of radius R, angles A1 and A2 |
||
110 A = ATN(1)*R*(360-ABS(A1-A2))/45 |
110 A = ATN(1)*R*(360-ABS(A1-A2))/45 |
||
120 RETURN</ |
120 RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 43.6332</pre> |
<pre> 43.6332</pre> |
||
Line 165: | Line 165: | ||
=={{header|C}}== |
=={{header|C}}== |
||
{{Trans|AWK}} |
{{Trans|AWK}} |
||
<syntaxhighlight lang="c"> |
|||
<lang c> |
|||
#define PI 3.14159265358979323846 |
#define PI 3.14159265358979323846 |
||
#define ABS(x) (x<0?-x:x) |
#define ABS(x) (x<0?-x:x) |
||
Line 177: | Line 177: | ||
printf("%.7f\n",arc_length(10, 10, 120)); |
printf("%.7f\n",arc_length(10, 10, 120)); |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 185: | Line 185: | ||
=={{header|C++}}== |
=={{header|C++}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |
||
< |
<syntaxhighlight lang="cpp">#include <iostream> |
||
#define _USE_MATH_DEFINES |
#define _USE_MATH_DEFINES |
||
Line 198: | Line 198: | ||
std::cout << "arc length: " << al << '\n'; |
std::cout << "arc length: " << al << '\n'; |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>arc length: 43.6332</pre> |
<pre>arc length: 43.6332</pre> |
||
Line 204: | Line 204: | ||
=={{header|D}}== |
=={{header|D}}== |
||
{{trans|C++}} |
{{trans|C++}} |
||
< |
<syntaxhighlight lang="d">import std.math; |
||
import std.stdio; |
import std.stdio; |
||
Line 213: | Line 213: | ||
void main() { |
void main() { |
||
writeln("arc length: ", arcLength(10.0, 10.0, 120.0)); |
writeln("arc length: ", arcLength(10.0, 10.0, 120.0)); |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>arc length: 43.6332</pre> |
<pre>arc length: 43.6332</pre> |
||
Line 219: | Line 219: | ||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
{{Trans|AWK}} |
{{Trans|AWK}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Length_of_an_arc; |
program Length_of_an_arc; |
||
Line 237: | Line 237: | ||
Readln; |
Readln; |
||
end. |
end. |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 244: | Line 244: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
< |
<syntaxhighlight lang="factor">USING: kernel math math.constants math.trig prettyprint ; |
||
: arc-length ( radius angle angle -- x ) |
: arc-length ( radius angle angle -- x ) |
||
- abs deg>rad 2pi swap - * ; |
- abs deg>rad 2pi swap - * ; |
||
10 10 120 arc-length .</ |
10 10 120 arc-length .</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 256: | Line 256: | ||
=={{header|FOCAL}}== |
=={{header|FOCAL}}== |
||
< |
<syntaxhighlight lang="focal">01.10 S A1=10 ;C SET PARAMETERS |
||
01.20 S A2=120 |
01.20 S A2=120 |
||
01.30 S R=10 |
01.30 S R=10 |
||
Line 264: | Line 264: | ||
02.01 C CALCULATE LENGTH OF ARC OF RADIUS R, ANGLES A1 AND A2 |
02.01 C CALCULATE LENGTH OF ARC OF RADIUS R, ANGLES A1 AND A2 |
||
02.10 S A=(360 - FABS(A2-A1)) * (3.14159 / 180) * R</ |
02.10 S A=(360 - FABS(A2-A1)) * (3.14159 / 180) * R</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>= 43.6332</pre> |
<pre>= 43.6332</pre> |
||
Line 270: | Line 270: | ||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
The Fortran subroutine contains the MAX(DIF, 360. - DIF) operation. Other solutions presented here correspond to different interpretations of the problem. This subroutine computes the length of the major arc, which is not necessarily equal to distance traveling counter-clockwise. |
The Fortran subroutine contains the MAX(DIF, 360. - DIF) operation. Other solutions presented here correspond to different interpretations of the problem. This subroutine computes the length of the major arc, which is not necessarily equal to distance traveling counter-clockwise. |
||
< |
<syntaxhighlight lang="fortran">*----------------------------------------------------------------------- |
||
* given: polar coordinates of two points on a circle of known radius |
* given: polar coordinates of two points on a circle of known radius |
||
* find: length of the major arc between these points |
* find: length of the major arc between these points |
||
Line 317: | Line 317: | ||
END |
END |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> first angle: 120.000000 second angle: 10.0000000 radius: 10.0000000 Length of major arc: 43.6332321 |
<pre> first angle: 120.000000 second angle: 10.0000000 radius: 10.0000000 Length of major arc: 43.6332321 |
||
Line 326: | Line 326: | ||
=={{Header|FreeBASIC}}== |
=={{Header|FreeBASIC}}== |
||
< |
<syntaxhighlight lang="freebasic"> |
||
#define DEG 0.017453292519943295769236907684886127134 |
#define DEG 0.017453292519943295769236907684886127134 |
||
Line 334: | Line 334: | ||
print arclength(10, 10, 120) |
print arclength(10, 10, 120) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 342: | Line 342: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 355: | Line 355: | ||
func main() { |
func main() { |
||
fmt.Println(arcLength(10, 10, 120)) |
fmt.Println(arcLength(10, 10, 120)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 364: | Line 364: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{Trans|Julia}} |
{{Trans|Julia}} |
||
< |
<syntaxhighlight lang="haskell">arcLength radius angle1 angle2 = (360.0 - (abs $ angle1 - angle2)) * pi * radius / 180.0 |
||
main = putStrLn $ "arcLength 10.0 10.0 120.0 = " ++ show (arcLength 10.0 10.0 120.0)</ |
main = putStrLn $ "arcLength 10.0 10.0 120.0 = " ++ show (arcLength 10.0 10.0 120.0)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>arcLength 10.0 10.0 120.0 = 43.63323129985823</pre> |
<pre>arcLength 10.0 10.0 120.0 = 43.63323129985823</pre> |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
< |
<syntaxhighlight lang="java">public static double arcLength(double r, double a1, double a2){ |
||
return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r; |
return (360.0 - Math.abs(a2-a1))*Math.PI/180.0 * r; |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
{{Trans|AWK}} |
{{Trans|AWK}} |
||
<syntaxhighlight lang="javascript"> |
|||
<lang JavaScript> |
|||
function arc_length(radius, angle1, angle2) { |
function arc_length(radius, angle1, angle2) { |
||
return (360 - Math.abs(angle2 - angle1)) * Math.PI / 180 * radius; |
return (360 - Math.abs(angle2 - angle1)) * Math.PI / 180 * radius; |
||
Line 383: | Line 383: | ||
console.log(arc_length(10, 10, 120).toFixed(7)); |
console.log(arc_length(10, 10, 120).toFixed(7)); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 398: | Line 398: | ||
In case you're wondering why `length` appears below where you might expect `abs`, rest assured that jq's `length` applied to a number yields its absolute value. |
In case you're wondering why `length` appears below where you might expect `abs`, rest assured that jq's `length` applied to a number yields its absolute value. |
||
< |
<syntaxhighlight lang="jq"># Output is in the same units as radius; angles are in degrees. |
||
def arclength(radius; angle1; angle2): |
def arclength(radius; angle1; angle2): |
||
def pi: 1 | atan * 4; |
def pi: 1 | atan * 4; |
||
Line 404: | Line 404: | ||
# The task: |
# The task: |
||
arclength(10; 10; 120)</ |
arclength(10; 10; 120)</syntaxhighlight> |
||
# {{out}} |
# {{out}} |
||
<pre> |
<pre> |
||
Line 412: | Line 412: | ||
=={{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. |
The task seems to be to find the distance along the circumference of the circle which is NOT swept out between the two angles. |
||
< |
<syntaxhighlight lang="julia"> |
||
arclength(r, angle1, angle2) = (360 - abs(angle2 - angle1)) * π/180 * r |
arclength(r, angle1, angle2) = (360 - abs(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 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Kotlin}}== |
=={{header|Kotlin}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
< |
<syntaxhighlight lang="scala">import kotlin.math.PI |
||
import kotlin.math.abs |
import kotlin.math.abs |
||
Line 429: | Line 429: | ||
val al = arcLength(10.0, 10.0, 120.0) |
val al = arcLength(10.0, 10.0, 120.0) |
||
println("arc length: $al") |
println("arc length: $al") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>arc length: 43.63323129985823</pre> |
<pre>arc length: 43.63323129985823</pre> |
||
Line 435: | Line 435: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{trans|D}} |
{{trans|D}} |
||
< |
<syntaxhighlight lang="lua">function arcLength(radius, angle1, angle2) |
||
return (360.0 - math.abs(angle2 - angle1)) * math.pi * radius / 180.0 |
return (360.0 - math.abs(angle2 - angle1)) * math.pi * radius / 180.0 |
||
end |
end |
||
Line 443: | Line 443: | ||
end |
end |
||
main()</ |
main()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>arc length: 43.633231299858</pre> |
<pre>arc length: 43.633231299858</pre> |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[MajorArcLength] |
||
MajorArcLength[r_, {a1_, a2_}] := Module[{d}, |
MajorArcLength[r_, {a1_, a2_}] := Module[{d}, |
||
d = Mod[Abs[a1 - a2], 360]; |
d = Mod[Abs[a1 - a2], 360]; |
||
Line 454: | Line 454: | ||
d Degree r |
d Degree r |
||
] |
] |
||
MajorArcLength[10, {10, 120}] // N</ |
MajorArcLength[10, {10, 120}] // N</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>43.6332</pre> |
<pre>43.6332</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import math, strformat |
||
const TwoPi = 2 * Pi |
const TwoPi = 2 * Pi |
||
Line 469: | Line 469: | ||
result = r * (if d >= Pi: d else: TwoPi - d) |
result = r * (if d >= Pi: d else: TwoPi - d) |
||
echo &"Arc length: {arcLength(10, degToRad(10.0), degToRad(120.0)):.5f}"</ |
echo &"Arc length: {arcLength(10, degToRad(10.0), degToRad(120.0)):.5f}"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 476: | Line 476: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{trans|Raku}} |
{{trans|Raku}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use utf8; |
use utf8; |
||
Line 500: | Line 500: | ||
[-90, 180, 10/π], |
[-90, 180, 10/π], |
||
[-90, 0, 10/π], |
[-90, 0, 10/π], |
||
[ 90, 0, 10/π];</ |
[ 90, 0, 10/π];</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Arc length: 43.63323 Parameters: (2.0943951, 0.1745329, 10.0000000) |
<pre>Arc length: 43.63323 Parameters: (2.0943951, 0.1745329, 10.0000000) |
||
Line 511: | Line 511: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">arclength</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle2</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">arclength</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle2</span><span style="color: #0000FF;">)</span> |
||
Line 517: | Line 517: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #0000FF;">?</span><span style="color: #000000;">arclength</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">120</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- 43.6332313</span> |
<span style="color: #0000FF;">?</span><span style="color: #000000;">arclength</span><span style="color: #0000FF;">(</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">120</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- 43.6332313</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">import math |
||
def arc_length(r, angleA, angleB): |
def arc_length(r, angleA, angleB): |
||
Line 526: | Line 526: | ||
</syntaxhighlight> |
|||
</lang> |
|||
<pre> |
<pre> |
||
radius = 10 |
radius = 10 |
||
Line 556: | Line 556: | ||
degrees to radians and a postfix ᵍ to convert gradians to radians. |
degrees to radians and a postfix ᵍ to convert gradians to radians. |
||
<lang |
<syntaxhighlight lang="raku" line>sub arc ( Real \a1, Real \a2, :r(:$radius) = 1 ) { |
||
( ([-] (a2, a1).map((* + τ) % τ)) + τ ) % τ × $radius |
( ([-] (a2, a1).map((* + τ) % τ)) + τ ) % τ × $radius |
||
} |
} |
||
Line 575: | Line 575: | ||
\(175ᵍ, -45ᵍ, :r(10/π)) { # test gradian parameters |
\(175ᵍ, -45ᵍ, :r(10/π)) { # test gradian parameters |
||
printf "Arc length: %8s Parameters: %s\n", arc(|$_).round(.000001), $_.raku |
printf "Arc length: %8s Parameters: %s\n", arc(|$_).round(.000001), $_.raku |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>Task example: from 120° counter-clockwise to 10° with 10 unit radius |
<pre>Task example: from 120° counter-clockwise to 10° with 10 unit radius |
||
Line 593: | Line 593: | ||
This REXX version handles angles (in degrees) that may be <big> > </big> 360º. |
This REXX version handles angles (in degrees) that may be <big> > </big> 360º. |
||
< |
<syntaxhighlight lang="rexx">/*REXX program calculates the length of an arc between two angles (stated in degrees).*/ |
||
parse arg radius angle1 angle2 . /*obtain optional arguments from the CL*/ |
parse arg radius angle1 angle2 . /*obtain optional arguments from the CL*/ |
||
if radius=='' | radius=="," then radius= 10 /*Not specified? Then use the default.*/ |
if radius=='' | radius=="," then radius= 10 /*Not specified? Then use the default.*/ |
||
Line 608: | Line 608: | ||
arcLength: procedure; parse arg r,a1,a2; #=360; return (#-abs(a1//#-a2//#)) * pi()/180 * r |
arcLength: procedure; parse arg r,a1,a2; #=360; return (#-abs(a1//#-a2//#)) * pi()/180 * r |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
pi: pi= 3.1415926535897932384626433832795; return pi /*use 32 digs (overkill).*/</ |
pi: pi= 3.1415926535897932384626433832795; return pi /*use 32 digs (overkill).*/</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 619: | Line 619: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
decimals(7) |
decimals(7) |
||
pi = 3.14159265 |
pi = 3.14159265 |
||
Line 629: | Line 629: | ||
x = (360 - fabs(angle2-angle1)) * pi / 180 * radius |
x = (360 - fabs(angle2-angle1)) * pi / 180 * radius |
||
return x |
return x |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 638: | Line 638: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
{{trans|C}} |
{{trans|C}} |
||
< |
<syntaxhighlight lang="ruby">def arc_length(radius, angle1, angle2) |
||
return (360.0 - (angle2 - angle1).abs) * Math::PI / 180.0 * radius |
return (360.0 - (angle2 - angle1).abs) * Math::PI / 180.0 * radius |
||
end |
end |
||
print "%.7f\n" % [arc_length(10, 10, 120)]</ |
print "%.7f\n" % [arc_length(10, 10, 120)]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>43.6332313</pre> |
<pre>43.6332313</pre> |
||
Line 648: | Line 648: | ||
=={{header|Vlang}}== |
=={{header|Vlang}}== |
||
{{trans|go}} |
{{trans|go}} |
||
< |
<syntaxhighlight lang="vlang">import math |
||
fn arc_length(radius f64, angle1 f64, angle2 f64) f64 { |
fn arc_length(radius f64, angle1 f64, angle2 f64) f64 { |
||
Line 655: | Line 655: | ||
fn main() { |
fn main() { |
||
println(arc_length(10, 10, 120)) |
println(arc_length(10, 10, 120)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>43.633231299858</pre> |
<pre>43.633231299858</pre> |
||
Line 661: | Line 661: | ||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="ecmascript">var arcLength = Fn.new { |r, angle1, angle2| (360 - (angle2 - angle1).abs) * Num.pi / 180 * r } |
||
System.print(arcLength.call(10, 10, 120))</ |
System.print(arcLength.call(10, 10, 120))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 671: | Line 671: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">def Pi = 3.14159265358979323846; |
||
func real ArcLen(Radius, Angle1, Angle2); \Length of major arc of circle |
func real ArcLen(Radius, Angle1, Angle2); \Length of major arc of circle |
||
Line 682: | Line 682: | ||
RlOut(0, ArcLen(10., 10., 120.)); |
RlOut(0, ArcLen(10., 10., 120.)); |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
Line 691: | Line 691: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang="zkl">fcn arcLength(radius, angle1, angle2){ |
||
(360.0 - (angle2 - angle1).abs()).toRad()*radius |
(360.0 - (angle2 - angle1).abs()).toRad()*radius |
||
} |
} |
||
println(arcLength(10,10,120));</ |
println(arcLength(10,10,120));</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |