3次元ベクトルクラスVector3ライブラリです。

Dependents:   Quaternion HAPS_GPS_Test_0002 GYSFDMAXB HAPS_EKF ... more

Revision:
3:3d5d3689521c
Parent:
1:8e112552bdfc
Child:
4:d68f06f4d554
--- a/Vector3.hpp	Fri Jun 09 19:54:15 2017 +0000
+++ b/Vector3.hpp	Sat Dec 16 02:38:25 2017 +0000
@@ -8,20 +8,20 @@
 class Vector3{
 public:
 	Vector3(){
-		x = 0.0;
-		y = 0.0;
-		z = 0.0;
+		x = 0.0f;
+		y = 0.0f;
+		z = 0.0f;
 	};
-	Vector3(double _x, double _y, double _z){
+	Vector3(float _x, float _y, float _z){
 		x = _x;
 		y = _y;
 		z = _z;
 	};
 
 public:
-	double x;
-	double y;
-	double z;
+	float x;
+	float y;
+	float z;
 
 	/**
 	*  @bref 3次元ベクトルの要素をコピー
@@ -33,7 +33,7 @@
 		return *this;
 	};
 
-	/**3次元ベクトルを足して代入する
+	/**3次元ベクトルを足して代入する*/
 	Vector3 operator+=(Vector3 vec){
 		x += vec.x;
 		y += vec.y;
@@ -41,7 +41,7 @@
 		return *this;
 	};
 
-	/**3次元ベクトルを引いて代入する*/
+	/** 3次元ベクトルを引いて代入する */
 	Vector3 operator-=(Vector3 vec){
 		x -= vec.x;
 		y -= vec.y;
@@ -51,16 +51,16 @@
 
 	/**3次元ベクトルを外積して代入する*/
 	Vector3 operator*=(Vector3 vec){
-		double _x = y*vec.z - z*vec.y;
-		double _y = z*vec.x - x*vec.z;
-		double _z = x*vec.y - y*vec.x;
+		float _x = y*vec.z - z*vec.y;
+		float _y = z*vec.x - x*vec.z;
+		float _z = x*vec.y - y*vec.x;
 		x = _x;
 		y = _y;
 		z = _z;
 		return *this;
 	}
 
-	Vector3 operator/=(double scalar){
+	Vector3 operator/=(float scalar){
 		x /= scalar;
 		y /= scalar;
 		z /= scalar;
@@ -82,13 +82,20 @@
 	/**
 	*  @bref Vector3クラスの各要素を初期化します。
 	*/
-	template<typename T>void set(T _x, T _y, T _z);
+	template<typename T>void Set(T _x, T _y, T _z);
 
 	/**
 	*  @bref 2つのVector3クラスのなす角を計算します.
 	*  @param 自分とのなす角度を計算するVector3クラスのインスタンス
 	*/
-	double Angle(Vector3 v);
+	float Angle(Vector3 v);
+	
+	/**
+	*  @bref 2つのVector3クラスのなす角を計算します.
+	*  @param 自分とのなす角度を計算するVector3クラスのインスタンス
+	*  @return 自分 * 相手となるベクトルを回転軸として符号付きのなす角度です
+	*/
+	float SgnAngle(Vector3 vec);
 
 	/**
 	*  @bref ゼロベクトルかどうか判定します.
@@ -96,7 +103,7 @@
 	*  @return 1ならゼロベクトル、0ならゼロベクトルではありません.
 	*/
 	int CheckZero(){
-		if (x == 0.0 && y == 0.0 && z == 0.0){
+		if (x == 0.0f && y == 0.0f && z == 0.0f){
 			return 1;
 		}
 		return 0;
@@ -105,14 +112,14 @@
 	/**
 	*  @bref 自身のノルムを計算して返します.
 	*/
-	double Norm();
+	float Norm();
 
 	/**
 	*  @bref  単位ベクトルにします
 	*/
 	void Normalize(){
-		double norm = sqrt(x*x + y*y + z*z);
-		if (norm != 0.0){
+		float norm = sqrt(x*x + y*y + z*z);
+		if (norm != 0.0f){
 			x /= norm;
 			y /= norm;
 			z /= norm;
@@ -122,6 +129,8 @@
 			return;
 		}
 	}
+
+	
 };
 
 /**
@@ -162,14 +171,14 @@
 *  @bref 内積を計算します
 *  @note ドットが使えなかったので%になりました。許してヒヤシンス
 */
-inline double operator%(Vector3 left, Vector3 right){
+inline float operator%(Vector3 left, Vector3 right){
 	return (left.x * right.x + left.y * right.y + left.z * right.z);
 }
 
 /**
 *  @bref Vector3クラスの各要素をスカラー倍します
 */
-inline Vector3 operator*(double scalar, Vector3 vec3){
+inline Vector3 operator*(float scalar, Vector3 vec3){
 	static Vector3 vec;
 	vec.x = scalar * vec3.x;
 	vec.y = scalar * vec3.y;
@@ -180,7 +189,7 @@
 /**
 *  @bref Vector3クラスの各要素をスカラー倍します
 */
-inline Vector3 operator*(Vector3 vec3, double scalar){
+inline Vector3 operator*(Vector3 vec3, float scalar){
 	static Vector3 vec;
 	vec.x = scalar * vec3.x;
 	vec.y = scalar * vec3.y;
@@ -191,7 +200,7 @@
 /**
 *  @bref  Vector3クラスの各要素をスカラーで割ります
 */
-inline Vector3 operator/(Vector3 vec3, double scalar){
+inline Vector3 operator/(Vector3 vec3, float scalar){
 	static Vector3 vec;
 	vec.x = vec3.x / scalar;
 	vec.y = vec3.y / scalar;
@@ -199,18 +208,26 @@
 	return vec;
 }
 
-template<typename T>void Vector3::set(T _x, T _y, T _z){
+template<typename T>void Vector3::Set(T _x, T _y, T _z){
 	x = _x;
 	y = _y;
 	z = _z;
 }
 
-inline double Vector3::Angle(Vector3 vec){
-	double r = (*this % vec) / (this->Norm() * vec.Norm());
+inline float Vector3::Angle(Vector3 vec){
+	float r = (*this % vec) / (this->Norm() * vec.Norm());
 	return acos(r);
 }
 
-inline double Vector3::Norm(){
+inline float Vector3::SgnAngle(Vector3 vec){
+	float 	theta = this->Angle(vec);
+	vec = *this * vec;
+	if(vec.z < 0) theta *= -1.0;
+	
+	return theta;
+}
+
+inline float Vector3::Norm(){
 	return sqrt(x*x + y*y + z*z);
 }