Length of an arc between two angles: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) |
MaiconSoft (talk | contribs) No edit summary |
||
Line 22: | Line 22: | ||
} |
} |
||
function abs(x) { if (x >= 0) { return x } else { return -x } } |
function abs(x) { if (x >= 0) { return x } else { return -x } } |
||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
43.6332313 |
|||
</pre> |
|||
=={{header|C}}== |
|||
{{Trans|AWK}} |
|||
<lang c> |
|||
#define PI 3.14159265358979323846 |
|||
#define ABS(x) (x<0?-x:x) |
|||
double arc_length(double radius, double angle1, double angle2) { |
|||
return (360 - ABS(angle2 - angle1)) * PI / 180 * radius; |
|||
} |
|||
void main() |
|||
{ |
|||
printf("%.7f\n",arc_length(10, 10, 120)); |
|||
} |
|||
</lang> |
</lang> |
||
{{out}} |
{{out}} |
||
Line 142: | Line 162: | ||
<pre> |
<pre> |
||
43.63323129985823 |
43.63323129985823 |
||
</pre> |
|||
=={{header|JavaScript}}== |
|||
{{Trans|AWK}} |
|||
<lang JavaScript> |
|||
function arc_length(radius, angle1, angle2) { |
|||
return (360 - Math.abs(angle2 - angle1)) * Math.PI / 180 * radius; |
|||
} |
|||
console.log(arc_length(10, 10, 120).toFixed(7)); |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
43.6332313 |
|||
</pre> |
</pre> |
||