class Coords::Cartesian3d
Public Class Methods
new(x, y, z)
click to toggle source
Calls superclass method
Coords::Cartesian2d::new
# File lib/coords/cartesian3d.rb, line 4 def initialize(x, y, z) super(x, y) @z = z end
Public Instance Methods
==(point)
click to toggle source
# File lib/coords/cartesian3d.rb, line 29 def ==(point) x.round(12) == point.x.round(12) && y.round(12) == point.y.round(12) && z.round(12) == point.z.round(12) end
distance_squared(point)
click to toggle source
# File lib/coords/cartesian3d.rb, line 13 def distance_squared(point) ((x - point.x).abs ** 2) + ((y - point.y).abs ** 2) + ((z - point.z).abs ** 2) end
rotate(rZ = 0, rX = 0, rY = 0)
click to toggle source
# File lib/coords/cartesian3d.rb, line 44 def rotate(rZ = 0, rX = 0, rY = 0) rotated_point = Cartesian3d.new(x, y, z) rotated_point.rotate!(rZ, rX, rY) rotated_point end
rotate!(rZ = 0, rX = 0, rY = 0)
click to toggle source
# File lib/coords/cartesian3d.rb, line 50 def rotate!(rZ = 0, rX = 0, rY = 0) # rotate clockwise around z axis d = Math.hypot(y, x) theta = Math.atan2(y, x) + rZ @x = d * Math.cos(theta) @y = d * Math.sin(theta) # rotate clockwise around x axis d = Math.hypot(y, z) theta = Math.atan2(z, y) + rX @y = d * Math.cos(theta) @z = d * Math.sin(theta) # rotate clockwise around y axis d = Math.hypot(x, z) theta = Math.atan2(x, z) + rY @z = d * Math.cos(theta) @x = d * Math.sin(theta) @x = x.round(12) @y = y.round(12) @z = z.round(12) end
to_s()
click to toggle source
# File lib/coords/cartesian3d.rb, line 17 def to_s x.to_s + ',' + y.to_s + ',' + z.to_s end
to_spherical()
click to toggle source
# File lib/coords/cartesian3d.rb, line 21 def to_spherical radius = Math.sqrt((x ** 2) + (y ** 2) + (z ** 2)); theta = Math.acos(z / radius) phi = Math.atan2(y, x) Spherical.new(radius.round(12), theta.round(12), phi.round(12)) end
translate(x2, y2, z2)
click to toggle source
# File lib/coords/cartesian3d.rb, line 33 def translate(x2, y2, z2) translated_point = Cartesian3d.new(x, y, z) translated_point.translate!(x2, y2, z2) translated_point end
translate!(x2, y2, z2)
click to toggle source
Calls superclass method
Coords::Cartesian2d#translate!
# File lib/coords/cartesian3d.rb, line 39 def translate!(x2, y2, z2) super(x2, y2) @z += z2 end
z()
click to toggle source
# File lib/coords/cartesian3d.rb, line 9 def z @z end