- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 154字
- 2021-06-30 14:46:02
Length and squared length
Like vectors, the squared length of a quaternion is the same as the dot product of the quaternion with itself. The length of a quaternion is the square root of the square length:
- Implement the lenSq function in quat.cpp and declare the function in quat.h:
float lenSq(const quat& q) {
return q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
}
- Implement the len function in quat.cpp. Don't forget to add the function declaration to quat.h:
float len(const quat& q) {
float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w;
if (lenSq< QUAT_EPSILON) {
return 0.0f;
}
return sqrtf(lenSq);
}
Quaternions that represent a rotation should always have a length of 1. In the next section, you will learn about unit quaternions, which always have a length of 1.
推薦閱讀
- Web程序設計及應用
- LabVIEW 2018 虛擬儀器程序設計
- PHP基礎案例教程
- Data Analysis with Stata
- Mastering Google App Engine
- Java程序設計入門
- Orleans:構建高性能分布式Actor服務
- 人工智能算法(卷1):基礎算法
- 并行編程方法與優化實踐
- 一覽眾山?。篈SP.NET Web開發修行實錄
- Python Penetration Testing Essentials
- Spring Microservices
- C語言從入門到精通(第4版)
- 鯤鵬架構入門與實戰
- Learning OpenCV 4 Computer Vision with Python 3