OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/gfx/geometry/vector3d_f.h" | 5 #include "ui/gfx/geometry/vector3d_f.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 | 10 |
| 11 namespace { |
| 12 const float kRadiansToDegrees = 180.0f / 3.14159265f; |
| 13 } |
| 14 |
11 namespace gfx { | 15 namespace gfx { |
12 | 16 |
13 Vector3dF::Vector3dF() | 17 Vector3dF::Vector3dF() |
14 : x_(0), | 18 : x_(0), |
15 y_(0), | 19 y_(0), |
16 z_(0) { | 20 z_(0) { |
17 } | 21 } |
18 | 22 |
19 Vector3dF::Vector3dF(float x, float y, float z) | 23 Vector3dF::Vector3dF(float x, float y, float z) |
20 : x_(x), | 24 : x_(x), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 82 |
79 Vector3dF ScaleVector3d(const Vector3dF& v, | 83 Vector3dF ScaleVector3d(const Vector3dF& v, |
80 float x_scale, | 84 float x_scale, |
81 float y_scale, | 85 float y_scale, |
82 float z_scale) { | 86 float z_scale) { |
83 Vector3dF scaled_v(v); | 87 Vector3dF scaled_v(v); |
84 scaled_v.Scale(x_scale, y_scale, z_scale); | 88 scaled_v.Scale(x_scale, y_scale, z_scale); |
85 return scaled_v; | 89 return scaled_v; |
86 } | 90 } |
87 | 91 |
| 92 float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
| 93 const gfx::Vector3dF& other) { |
| 94 return acos(gfx::DotProduct(base, other) / base.Length() / other.Length()) * |
| 95 kRadiansToDegrees; |
| 96 } |
| 97 |
| 98 float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, |
| 99 const gfx::Vector3dF& other, |
| 100 const gfx::Vector3dF& normal) { |
| 101 float angle = AngleBetweenVectorsInDegrees(base, other); |
| 102 gfx::Vector3dF cross(base); |
| 103 cross.Cross(other); |
| 104 |
| 105 // If the dot product of this cross product is normal, it means that the |
| 106 // shortest angle between |base| and |other| was counterclockwise with respect |
| 107 // to the surface represented by |normal| and this angle must be reversed. |
| 108 if (gfx::DotProduct(cross, normal) > 0.0f) |
| 109 angle = 360.0f - angle; |
| 110 return angle; |
| 111 } |
| 112 |
88 } // namespace gfx | 113 } // namespace gfx |
OLD | NEW |