/ fdf / fdf / srcs / rotate.c
rotate.c
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   rotate.c                                           :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: gychoi <gychoi@student.42seoul.kr>         +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/01/01 20:08:39 by gychoi            #+#    #+#             */
 9  /*   Updated: 2023/01/01 20:09:55 by gychoi           ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include "fdf.h"
14  
15  void	rotate_x(t_point *point, double theta)
16  {
17  	double	new_x;
18  	double	new_y;
19  	double	new_z;
20  
21  	new_x = point->x;
22  	new_y = (point->y * cos(theta)) + (point->z * sin(theta) * -1);
23  	new_z = (point->y * sin(theta)) + (point->z * cos(theta));
24  	point->x = new_x;
25  	point->y = new_y;
26  	point->z = new_z;
27  }
28  
29  void	rotate_y(t_point *point, double theta)
30  {
31  	double	new_x;
32  	double	new_y;
33  	double	new_z;
34  
35  	new_x = (point->x * cos(theta)) + (point->z * sin(theta));
36  	new_y = point->y;
37  	new_z = (point->x * sin(theta) * -1) + (point->z * cos(theta));
38  	point->x = new_x;
39  	point->y = new_y;
40  	point->z = new_z;
41  }
42  
43  void	rotate_z(t_point *point, double theta)
44  {
45  	double	new_x;
46  	double	new_y;
47  	double	new_z;
48  
49  	new_x = (point->x * cos(theta)) + (point->y * sin(theta) * -1);
50  	new_y = (point->x * sin(theta)) + (point->y * cos(theta));
51  	new_z = point->z;
52  	point->x = new_x;
53  	point->y = new_y;
54  	point->z = new_z;
55  }