Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Averages-Mean-angle/PHP/averages-mean-angle.php
Normal file
23
Task/Averages-Mean-angle/PHP/averages-mean-angle.php
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
$samples = array(
|
||||
'1st' => array(350, 10),
|
||||
'2nd' => array(90, 180, 270, 360),
|
||||
'3rd' => array(10, 20, 30)
|
||||
);
|
||||
|
||||
foreach($samples as $key => $sample){
|
||||
echo 'Mean angle for ' . $key . ' sample: ' . meanAngle($sample) . ' degrees.' . PHP_EOL;
|
||||
}
|
||||
|
||||
function meanAngle ($angles){
|
||||
$y_part = $x_part = 0;
|
||||
$size = count($angles);
|
||||
for ($i = 0; $i < $size; $i++){
|
||||
$x_part += cos(deg2rad($angles[$i]));
|
||||
$y_part += sin(deg2rad($angles[$i]));
|
||||
}
|
||||
$x_part /= $size;
|
||||
$y_part /= $size;
|
||||
return rad2deg(atan2($y_part, $x_part));
|
||||
}
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue