Skip to content

Commit

Permalink
changed rotation logic, pi is calculated by acos(-1) and the input ar…
Browse files Browse the repository at this point in the history
…gument of rotation is degree
  • Loading branch information
Tsunghao-C committed Aug 27, 2024
1 parent 1b44e10 commit c53eed0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions srcs/vector/vector_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tsuchen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 13:33:30 by tsuchen #+# #+# */
/* Updated: 2024/08/27 14:28:36 by tsuchen ### ########.fr */
/* Updated: 2024/08/27 15:32:46 by tsuchen ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -51,9 +51,13 @@ void vec_rotate(t_vec *vec, double angle)
{
double new_x;
double new_y;
double pi;
double angle_r;

new_x = vec->x * cos(angle) - vec->y * sin(angle);
new_y = vec->x * sin(angle) + vec->y * cos(angle);
pi = acos(-1);
angle_r = angle * pi / 180;
new_x = vec->x * cos(angle_r) - vec->y * sin(angle_r);
new_y = vec->x * sin(angle_r) + vec->y * cos(angle_r);
vec->x = new_x;
vec->y = new_y;
}

0 comments on commit c53eed0

Please sign in to comment.