Class: Matrix
- Inherits:
-
Object
- Object
- Matrix
- Defined in:
- lib/ext.rb
Class Method Summary collapse
Instance Method Summary collapse
- #multi_new(rhs) ⇒ Object (also: #*)
Class Method Details
.from_axis(axis, angle) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ext.rb', line 6 def self.from_axis(axis, angle) Util3D::check_arg_type(Vector3, axis) Util3D::check_arg_type(Numeric, angle) return Matrix[ [axis.x*axis.x*(1 - Math.cos(angle)) + Math.cos(angle), axis.x*axis.y*(1 - Math.cos(angle)) + axis.z*Math.sin(angle), axis.x*axis.z*(1 - Math.cos(angle)) - axis.y*Math.sin(angle)], [axis.x*axis.y*(1 - Math.cos(angle)) - axis.z*Math.sin(angle), axis.y*axis.y*(1 - Math.cos(angle)) + Math.cos(angle), axis.y*axis.z*(1 - Math.cos(angle)) + axis.x*Math.sin(angle)], [axis.x*axis.z*(1 - Math.cos(angle)) + axis.y*Math.sin(angle), axis.y*axis.z*(1 - Math.cos(angle)) - axis.x*Math.sin(angle), axis.z*axis.z*(1 - Math.cos(angle)) + Math.cos(angle)]] end |
.from_quat(quat) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ext.rb', line 22 def self.from_quat(quat) Util3D::check_arg_type(Quat, quat) qw = quat.w qx = quat.x qy = quat.y qz = quat.z x2 = 2.0 * qx * qx; y2 = 2.0 * qy * qy; z2 = 2.0 * qz * qz; xy = 2.0 * qx * qy; yz = 2.0 * qy * qz; zx = 2.0 * qz * qx; wx = 2.0 * qw * qx; wy = 2.0 * qw * qy; wz = 2.0 * qw * qz; return Matrix[ [ 1.0 - y2 - z2, xy + wz, zx - wy], [ xy - wz, 1.0 - z2 - x2, yz + wx], [ zx + wy, yz - wx, 1.0 - x2 - y2]] end |
Instance Method Details
#multi_new(rhs) ⇒ Object Also known as: *
46 47 48 49 50 51 52 |
# File 'lib/ext.rb', line 46 def multi_new(rhs) if(rhs.kind_of?(Vector3)) ans = self.multi_inner(rhs.to_column_vector) return Vector3.new(ans[0,0], ans[1,0], ans[2,0]) end multi_inner(rhs) end |