Example #1
0
/**
 * Gets the distances of each point from the circle
 * @param  array $center The center of the circle
 * @param  float $radius Radius of the circle
 * @param  array  $lines The gcode lines
 * @return array         An array of the errors
 */
function getCircleErrors($center, $radius, $lines)
{
    $errors = array();
    foreach ($lines as $line) {
        $vec = array($center['X'] - $line['X'], $center['Y'] - $line['Y']);
        $length = vector_magnitude($vec);
        $errors[] = abs($length - $radius);
    }
    return $errors;
}
/**
 * Calculates the angle between two vectors
 *
 * e.g. angleBetween(['X'=> 0, 'Y' => 0] & ['X' => 1, 'Y' => 1]);
 * @param  array  $v1 Vector 1
 * @param  array  $v2 Vector 2
 * @return float      The angle in radians
 */
function angleBetween($v1, $v2)
{
    $angle = acos(vector_dot_product($v1, $v2) / (vector_magnitude($v1) * vector_magnitude($v2))) + 3 * (M_PI / 4);
    return $angle > M_PI ? $angle - M_PI : $angle;
}