fennec
Loading...
Searching...
No Matches
trigonometric.h
Go to the documentation of this file.
1// =====================================================================================================================
2// fennec, a free and open source game engine
3// Copyright © 2025 Medusa Slockbower
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17// =====================================================================================================================
18
30
31#ifndef FENNEC_MATH_TRIGONOMETRIC_H
32#define FENNEC_MATH_TRIGONOMETRIC_H
33
146
147#include <fennec/math/detail/_math.h>
148#include <fennec/math/vector.h>
149#include <fennec/lang/types.h>
150
151namespace fennec
152{
153
154// Angle Conversions ===================================================================================================
155
158
167template<typename genType>
168constexpr genType radians(genType degrees) {
169 return genType(degrees * 0.01745329251994329576923690768489);
170}
171
172
181template<typename genType>
182constexpr genType degrees(genType radians) {
183 return genType(radians * 57.29577951308232087679815481410517);
184}
185
187
188
189
190// Trigonometric ======================================================================================================
191
194
203template<typename genType>
204constexpr genType sin(genType x) {
205 return ::sin(x);
206}
207
208
217template<typename genType>
218constexpr genType cos(genType x) {
219 return ::cos(x);
220}
221
222
231template<typename genType>
232constexpr genType tan(genType x) {
233 return ::tan(x);
234}
235
237
238
239
242
252template<typename genType>
253constexpr genType asin(genType x) {
254 return ::asin(x);
255}
256
257
267template<typename genType>
268constexpr genType acos(genType x) {
269 return ::acos(x);
270}
271
272
282template<typename genType>
283constexpr genType atan(genType y_over_x) {
284 return ::atan(y_over_x);
285}
286
287
298template<typename genType>
299constexpr genType atan(genType y, genType x) {
300 return ::atan2(y, x);
301}
302
304
305
306
307// Hyperbolic Functions ================================================================================================
308
311
319template<typename genType>
320constexpr genType sinh(genType x) {
321 return ::sinh(x);
322}
323
324
331template<typename genType>
332constexpr genType cosh(genType x) {
333 return ::cosh(x);
334}
335
336
343template<typename genType, size_t...i>
344constexpr genType tanh(genType x) {
345 return ::tanh(x);
346}
347
349
350
351
354
362template<typename genType, size_t...i>
363constexpr genType asinh(genType x) {
364 return ::asinh(x);
365}
366
367
375template<typename genType, size_t...i>
376constexpr genType acosh(genType x) {
377 return ::acosh(x);
378}
379
380
388template<typename genType, size_t...i>
389constexpr genType atanh(genType x) {
390 return ::atanh(x);
391}
392
394
395
396
397// Internal ============================================================================================================
398
399#ifndef FENNEC_DOXYGEN
400template<typename genType, size_t...i>
401constexpr vector<genType, i...> radians(const vector<genType, i...>& degrees) {
402 return vector<genType, i...>(degrees * 0.01745329251994329576923690768489);
403}
404
405template<typename genType, size_t...i>
406constexpr vector<genType, i...> degrees(const vector<genType, i...>& radians) {
407 return genType(radians * 57.29577951308232087679815481410517);
408}
409
410template<typename genType, size_t...i>
411constexpr vector<genType, i...> sin(const vector<genType, i...>& x) {
412 return vector<genType, i...>(fennec::sin(x[i]) ...);
413}
414
415template<typename genType, size_t...i>
416constexpr vector<genType, i...> cos(const vector<genType, i...>& x) {
417 return vector<genType, i...>(fennec::cos(x[i]) ...);
418}
419
420template<typename genType, size_t...i>
421constexpr vector<genType, i...> tan(const vector<genType, i...>& x) {
422 return vector<genType, i...>(fennec::tan(x[i]) ...);
423}
424
425template<typename genType, size_t...i>
426constexpr vector<genType, i...> asin(const vector<genType, i...>& x) {
427 return vector<genType, i...>(fennec::asin(x[i]) ...);
428}
429
430template<typename genType, size_t...i>
431constexpr vector<genType, i...> acos(const vector<genType, i...>& x) {
432 return vector<genType, i...>(fennec::acos(x[i]) ...);
433}
434
435template<typename genType, size_t...i>
436constexpr vector<genType, i...> atan(const vector<genType, i...>& y_over_x) {
437 return vector<genType, i...>(fennec::atan(y_over_x[i]) ...);
438}
439
440template<typename genType, size_t...i>
441constexpr vector<genType, i...> atan(const vector<genType, i...>& y, const vector<genType, i...>& x) {
442 return vector<genType, i...>(fennec::atan(y[i], x[i]) ...);
443}
444
445template<typename genType, size_t...i>
446constexpr vector<genType, i...> sinh(const vector<genType, i...>& x) {
447 return vector<genType, i...>(fennec::sinh(x[i]) ...);
448}
449
450template<typename genType, size_t...i>
451constexpr vector<genType, i...> cosh(const vector<genType, i...>& x) {
452 return vector<genType, i...>(fennec::cosh(x[i]) ...);
453}
454
455template<typename genType, size_t...i>
456constexpr vector<genType, i...> tanh(const vector<genType, i...>& x) {
457 return vector<genType, i...>(fennec::tanh(x[i]) ...);
458}
459
460template<typename genType, size_t...i>
461constexpr vector<genType, i...> asinh(const vector<genType, i...>& x) {
462 return vector<genType, i...>(fennec::asinh(x[i]) ...);
463}
464
465template<typename genType, size_t...i>
466constexpr vector<genType, i...> acosh(const vector<genType, i...>& x) {
467 return vector<genType, i...>(fennec::acosh(x[i]) ...);
468}
469
470template<typename genType, size_t...i>
471constexpr vector<genType, i...> atanh(const vector<genType, i...>& x) {
472 return vector<genType, i...>(fennec::atanh(x[i]) ...);
473}
474#endif
475
476
477
478}
479
480
481
482#endif // FENNEC_MATH_TRIGONOMETRIC_H
constexpr genType y()
Definition constants.h:672
constexpr genType asinh(genType x)
The Inverse Hyperbolic Sine Function.
Definition trigonometric.h:363
constexpr genType atanh(genType x)
The Inverse Hyperbolic Tangent Function.
Definition trigonometric.h:389
constexpr genType degrees(genType radians)
Converts to , i.e., .
Definition trigonometric.h:182
constexpr genType acos(genType x)
Arc Cosine. Returns an angle whose cosine is /a x.
Definition trigonometric.h:268
constexpr genType atan(genType y_over_x)
Arc Tangent. Returns an angle whose tangent is /a y_over_x.
Definition trigonometric.h:283
constexpr genType tan(genType x)
The Standard Trigonometric Tangent.
Definition trigonometric.h:232
constexpr genType cosh(genType x)
Returns the Hyperbolic Cosine Function, .
Definition trigonometric.h:332
constexpr genType radians(genType degrees)
Converts to , i.e., .
Definition trigonometric.h:168
constexpr genType tanh(genType x)
Returns the Hyperbolic Tangent Function, .
Definition trigonometric.h:344
constexpr genType sin(genType x)
The standard trigonometric sine.
Definition trigonometric.h:204
constexpr genType acosh(genType x)
The Inverse Hyperbolic Cosine Function.
Definition trigonometric.h:376
constexpr genType asin(genType x)
Arc Sine. Returns an angle whose sine is /a x.
Definition trigonometric.h:253
constexpr genType cos(genType x)
The Standard Trigonometric Cosine.
Definition trigonometric.h:218
constexpr genType sinh(genType x)
Returns the Hyperbolic Sine Function, .
Definition trigonometric.h:320
Types
the Vectors