miniRT
By Marcelo Magalhães and Ygor G. Sena, 2023.
tuples.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* tuples.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: yde-goes <yde-goes@student.42sp.org.br> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2023/03/09 21:09:16 by mdias-ma #+# #+# */
9 /* Updated: 2023/06/16 13:40:24 by yde-goes ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
14 #ifndef TUPLES_H
15 # define TUPLES_H
16 
17 # include <math.h>
18 # include <stdlib.h>
19 
32 typedef struct s_tuple
33 {
34  double x;
35  double y;
36  double z;
37  double w;
39 
44 typedef t_tuple t_point;
45 
50 typedef t_tuple t_vector;
51 
62 typedef struct s_color
63 {
64  double red;
65  double green;
66  double blue;
68 
69 /* ************************************************************************** */
70 /* MODELS.C */
71 /* ************************************************************************** */
72 
84 t_tuple tuple(double x, double y, double z, double w);
85 
97 t_tuple point(double x, double y, double z);
98 
110 t_tuple vector(double x, double y, double z);
111 
112 /* ************************************************************************** */
113 /* BASIC_MATH.C */
114 /* ************************************************************************** */
115 
127 t_tuple add(t_tuple a, t_tuple b);
128 
144 
155 
165 t_tuple multiply(t_tuple a, double scalar);
166 
176 t_tuple divide(t_tuple a, double scalar);
177 
178 /* ************************************************************************** */
179 /* VECTOR_MATH.C */
180 /* ************************************************************************** */
181 
190 double magnitude(t_tuple vector);
191 
201 
202 /* Get the value that indicates the relationship between 2 vectors,
203  * in terms of direction. */
204 
218 double dot(t_tuple a, t_tuple b);
219 
233 
244 t_tuple reflect(t_tuple in, t_tuple normal);
245 
246 /* ************************************************************************** */
247 /* COLORS.C */
248 /* ************************************************************************** */
249 
260 t_color new_color(double red, double green, double blue);
261 
273 
285 
297 t_color multiply_color(t_color color, double scalar);
298 
311 
312 #endif
The struct s_color stores the color values of ray tracing. It contains a field for red,...
Definition: tuples.h:63
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordin...
Definition: tuples.h:33
t_color subtract_color(t_color a, t_color b)
The function subtract_color() decreases the intensity of each RGB color component of a and b....
Definition: colors.c:31
struct s_tuple t_tuple
Tuple means a list of ordered things. The struct t_tuple stores coordinates for a left-handed coordin...
t_tuple vector(double x, double y, double z)
This function is a simplification of the function tuple(). It will create a point with the given coor...
Definition: models.c:25
struct s_color t_color
The struct s_color stores the color values of ray tracing. It contains a field for red,...
t_tuple t_point
The type t_point is a syntatic sugar for any structure t_tuple whose w's field equals to 1,...
Definition: tuples.h:44
t_tuple normalize(t_tuple vector)
The function normalize() takes an arbitrary vector and converts it into a unit vector....
Definition: vector_math.c:27
t_color hadamard_product(t_color a, t_color b)
The function hadamard_product() blends two color together by multiplying corresponding components of ...
Definition: colors.c:49
t_color new_color(double red, double green, double blue)
The function new_color() instances a new color of struct type s_color with the given values passed as...
Definition: colors.c:15
t_tuple tuple(double x, double y, double z, double w)
The function tuple() instances a new material of struct type t_tuple with the given values passed as ...
Definition: models.c:15
t_tuple cross(t_tuple a, t_tuple b)
The function cross() multiplies vectors, instead of tuples. After all, the ray traces only needs a th...
Definition: vector_math.c:50
t_color add_color(t_color a, t_color b)
The function add_color() combines the intensity of each RGB color component of a and b....
Definition: colors.c:22
t_tuple divide(t_tuple a, double scalar)
The function divide() divides a vector by a scalar value, i.e., it changes the vector length uniforml...
Definition: basic_math.c:55
t_tuple negate(t_tuple a)
The function negate() returns the opposite vector of a given vector passed as parameter....
Definition: basic_math.c:35
t_tuple subtract(t_tuple a, t_tuple b)
The subtract() function subtract two tuples. A vector minus a point results in a point (w values: 1 -...
Definition: basic_math.c:25
t_tuple add(t_tuple a, t_tuple b)
The add() function sums two tuples. A vector plus a point results in a point (w values: 1 + 0 = 1)....
Definition: basic_math.c:15
t_color multiply_color(t_color color, double scalar)
The function multiply_color() scales the intensities of each RGB color component of the parameter col...
Definition: colors.c:40
t_tuple reflect(t_tuple in, t_tuple normal)
This function returns the result of reflecting the in vector around the normal vector.
Definition: vector_math.c:59
t_tuple point(double x, double y, double z)
This function is a simplification of the function tuple(). It will create a point with the given coor...
Definition: models.c:20
double magnitude(t_tuple vector)
The function magnitude() gets the magnitude or length of a given vector passed as parameter....
Definition: vector_math.c:15
t_tuple multiply(t_tuple a, double scalar)
The function multiply() multiplies a vector by a scalar value, i.e., it changes the vector length uni...
Definition: basic_math.c:45
t_tuple t_vector
The type t_point is a syntatic sugar for any structure t_tuple whose w's field equals to 0,...
Definition: tuples.h:50
double dot(t_tuple a, t_tuple b)
The function dot() computes the sum of the products of the corresponding components of each vector....
Definition: vector_math.c:40