Skip to content

Commit

Permalink
sqrt() is a lot cheaper than cos() or sin()
Browse files Browse the repository at this point in the history
  • Loading branch information
tombrazier committed Jun 18, 2022
1 parent 76f1f9d commit 361268b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Marlin/src/gcode/motion/G2_G3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,10 @@ void plan_arc(
// Compute exact location by applying transformation matrix from initial radius vector(=-offset).
// To reduce stuttering, the sin and cos could be computed at different times.
// For now, compute both at the same time.
const float cos_Ti = cos(i * theta_per_segment), sin_Ti = sin(i * theta_per_segment);
const float angle = i * theta_per_segment,
cos_Ti = cos(angle),
abs_sin_Ti = SQRT(1 - cos_Ti * cos_Ti),
sin_Ti = angle > M_PI || (angle < 0.0f && angle > -M_PI) ? -abs_sin_Ti : abs_sin_Ti;
rvec.a = -offset[0] * cos_Ti + offset[1] * sin_Ti;
rvec.b = -offset[0] * sin_Ti - offset[1] * cos_Ti;
}
Expand Down

0 comments on commit 361268b

Please sign in to comment.