- Hands-On C++ Game Animation Programming
- Gabor Szauer
- 242字
- 2021-06-30 14:45:50
Dot product
The dot product is used to measure how similar two vectors are. Given two vectors, the dot product returns a scalar value. The result of the dot product has the following properties:
- It is positive if the vectors point in the same direction.
- It is negative if the vectors point in opposite directions.
- It is 0 if the vectors are perpendicular.
If both input vectors have a unit length (you will learn about unit length vectors in the Normal vectors section of this chapter), the dot product will have a range of -1 to 1.
The dot product between two vectors, A and B, is equal to the length of A multiplied by the length of B multiplied by the cosine of the angle between the two vectors:

The easiest way to calculate the dot product is to sum the products of like components in the input vectors:
Implement the dot function in vec3.cpp. Don't forget to add the function definition to vec3.h:
float dot(const vec3 &l, const vec3 &r) {
return l.x * r.x + l.y * r.y + l.z * r.z;
}
The dot product is one of the most used operations for video games. It's often used to check angles and in lighting calculations.
With the dot product, you have implemented the common component-wise operations of vectors. Next, you will learn about some of the non-component-wise operations that can be performed on vectors.
- Designing Machine Learning Systems with Python
- ExtGWT Rich Internet Application Cookbook
- Learn Blockchain Programming with JavaScript
- 摩登創客:與智能手機和平板電腦共舞
- WebAssembly實戰
- Django Design Patterns and Best Practices
- C語言程序設計
- 零基礎輕松學SQL Server 2016
- Learning OpenStack Networking(Neutron)
- C語言程序設計
- HTML 5與CSS 3權威指南(第3版·上冊)
- 愛上micro:bit
- 零基礎學C語言第2版
- Image Processing with ImageJ
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理