Last active
August 29, 2015 13:57
-
-
Save jimfoltz/9595430 to your computer and use it in GitHub Desktop.
Projectile Motion Animation SketchUp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cannon | |
def initialize(bearing, elev, velocity) | |
@item = Sketchup.active_model.entities[0] | |
@t = 0 | |
@v = velocity.to_f | |
@angle = elev.to_f | |
@bearing = bearing.to_f | |
@vy = @v * Math::cos(@angle.degrees) | |
@vz = @v * Math::sin(@angle.degrees) | |
#@zi = @item.bounds.center.z | |
@zi = @item.transformation.to_a[-2] | |
@last_pt = nil | |
end | |
def nextFrame(view) | |
x = 0 | |
y = @vy * @t | |
z = (@vz * @t) + 0.5 * -10.0 * (@t ** 2) | |
pt = Geom::Point3d.new(x, y, z) | |
t = Geom::Transformation.new(pt) | |
@item.transformation = t | |
if @last_pt | |
#Sketchup.active_model.entities.add_cpoint @item.bounds.center | |
Sketchup.active_model.entities.add_line pt, @last_pt | |
end | |
@last_pt = pt | |
@t += 0.2 | |
if z < 0 | |
return false | |
else | |
return true | |
end | |
end | |
end | |
def fire(bearing, angle, velocity) | |
Sketchup.active_model.active_view.animation = Cannon.new(bearing, angle, velocity) | |
nil | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment