KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
KisaragiMath.hpp
[詳解]
1#pragma once
2
3/**
4 * @file KisaragiMath.hpp
5 * @brief 独自のMathを提供します
6 * @author 樺澤陽向
7 * @date 2025/05/09
8 * @since
9
10
11
12 Vector2型(削除済み)の関数を削除し、Vector2Dに対応させたものをPrimitiveMath.hppに移動
13 */
14
15#include <cassert>
16
17namespace Kisaragi_Lib
18{
19 //double型 π.
20 static const double PI = 3.1415926535897932384626433832795;
21 //float型 π.
22 static const float PI_F = 3.1415926535897932384626433832795f;
23
24 //double型 π * 2.
25 static const double TWO_PI = 3.1415926535897932384626433832795 * 2.0;
26 //float型 π * 2.
27 static const float TWO_PI_F = 3.1415926535897932384626433832795f * 2.0f;
28
29
30 static const double DEGREES_HALF = 180.0;
31
32
33
34 /// <summary>
35 /// 汎用計算クラス
36 /// </summary>
37 /// @since ver1.0.0 Vector2型(削除済み)の関数を削除し、Vector2Dに対応させたものをPrimitiveMath.hppに移動
38 class Math
39 {
40 public:
41
42 /// <summary>
43 /// ラジアン値を角度に変換する.
44 /// </summary>
45 /// <param name="_radian">ラジアン値</param>
46 /// <returns>角度</returns>
47 static double RadianToDegree(const double& _radian)
48 {
49 return (_radian * DEGREES_HALF / PI);
50 }
51
52 /// <summary>
53 /// 角度をラジアン値に変換する.
54 /// </summary>
55 /// <param name="_degree">角度</param>
56 /// <returns>ラジアン値</returns>
57 static double DegreeToRadian(const double& _degree)
58 {
59 return (_degree * PI / DEGREES_HALF);
60 }
61
62 /// <summary>
63 /// 正規化された方向ベクトルから角度を求める.
64 /// </summary>
65 /// <param name="_vecX">正規化されたX方向のベクトル</param>
66 /// <param name="_vecY">正規化されたY方向のベクトル</param>
67 /// <returns>角度</returns>
68 static double VectorToDegree(const double& _vecX, const double& _vecY)
69 {
70 return RadianToDegree(atan2(_vecY, _vecX));
71 }
72
73
74
75 /// <summary>
76 /// 正規化された方向ベクトルからラジアン値を求める.
77 /// </summary>
78 /// <param name="_vecX">正規化されたX方向のベクトル</param>
79 /// <param name="_vecY">正規化されたY方向のベクトル</param>
80 /// <returns>ラジアン値</returns>
81 static double VectorToRadian(const double& _vecX, const double& _vecY)
82 {
83 return atan2(_vecY, _vecX);
84 }
85
86
87
88 /// <summary>
89 /// ベクトルを正規化する.
90 /// </summary>
91 /// <param name="_vecX">正規化したいベクトル</param>
92 /// <param name="_vecY">正規化したいベクトル</param>
93 template <class T>
94 static void Normalize(T* _vecX, T* _vecY)
95 {
96 double vecLength = sqrt((*_vecX * *_vecX) + (*_vecY * *_vecY));
97 //正規化されている(ベクトルの長さが1)なら.
98 if (vecLength == 1)
99 {
100 //処理しない
101 return;
102 }
103
104 //正規化処理.
105 if (*_vecX != 0)
106 {
107 *_vecX = (*_vecX / vecLength);
108 }
109
110 if (*_vecY != 0)
111 {
112 *_vecY = (*_vecY / vecLength);
113 }
114
115 }
116
117
118 /// <summary>
119 /// べき乗,累乗
120 /// </summary>
121 /// <typeparam name="T">計算したい型</typeparam>
122 /// <param name="_num">値</param>
123 /// <param name="_cnt">回数</param>
124 /// <returns>べき乗の結果</returns>
125 template<class T>
126 static T Pow(const T& _num ,const unsigned int& _cnt)
127 {
128 //0以下は想定してないっす.
129 assert(_cnt > 0);
130
131 T tmp = _num;
132
133 //_cnt = 1の場合は代入だけして返すっす.
134 for (int i = 1; i < _cnt; i++)
135 {
136 tmp *= _num;
137 }
138
139 return tmp;
140 }
141 };
142}
汎用計算クラス
Definition KisaragiMath.hpp:39
static T Pow(const T &_num, const unsigned int &_cnt)
べき乗,累乗
Definition KisaragiMath.hpp:126
static double DegreeToRadian(const double &_degree)
角度をラジアン値に変換する.
Definition KisaragiMath.hpp:57
static double VectorToRadian(const double &_vecX, const double &_vecY)
正規化された方向ベクトルからラジアン値を求める.
Definition KisaragiMath.hpp:81
static double RadianToDegree(const double &_radian)
ラジアン値を角度に変換する.
Definition KisaragiMath.hpp:47
static void Normalize(T *_vecX, T *_vecY)
ベクトルを正規化する.
Definition KisaragiMath.hpp:94
static double VectorToDegree(const double &_vecX, const double &_vecY)
正規化された方向ベクトルから角度を求める.
Definition KisaragiMath.hpp:68
Definition Accessor.hpp:110
static const double TWO_PI
Definition KisaragiMath.hpp:25
static const float TWO_PI_F
Definition KisaragiMath.hpp:27
static const double PI
Definition KisaragiMath.hpp:20
static const float PI_F
Definition KisaragiMath.hpp:22
static const double DEGREES_HALF
Definition KisaragiMath.hpp:30