From c53eed040352e87838f56230a8f89fc67a82172d Mon Sep 17 00:00:00 2001 From: Tsunghao Date: Tue, 27 Aug 2024 15:38:10 +0200 Subject: [PATCH] changed rotation logic, pi is calculated by acos(-1) and the input argument of rotation is degree --- srcs/vector/vector_2.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/srcs/vector/vector_2.c b/srcs/vector/vector_2.c index 1ec1215..03dc592 100644 --- a/srcs/vector/vector_2.c +++ b/srcs/vector/vector_2.c @@ -6,7 +6,7 @@ /* By: tsuchen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 */ /* */ /* ************************************************************************** */ @@ -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; }