language: PHP (php 5.4.4)
date: 528 days 8 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
 
function toCoords($center, $radius, $angle) {
    $radians = ($angle/180) * M_PI;
    $x = $center[0] + cos($radians) * $radius;
    $y = $center[1] + sin($radians) * $radius;
    return array($x, $y);
}
 
function arc($center, $radius, $startAngle, $endAngle) {
    $angle = $startAngle;
    $coords = toCoords($center, $radius, $angle);
    $path = "M " . $coords[0] . " " . $coords[1];
    while($angle<=$endAngle) {
        $coords = toCoords($center, $radius, $angle);
        $path .= " L " . $coords[0] . " " . $coords[1];
        $angle += 6;
    }
    return $path;
}
 
// test it
print_r( arc(array(0,0),10,0,30) );
 
?>