Skip to content

Instantly share code, notes, and snippets.

@harmishhk
Created August 10, 2015 13:05
Show Gist options
  • Save harmishhk/8a5a8f8ffdcdb89b58bf to your computer and use it in GitHub Desktop.
Save harmishhk/8a5a8f8ffdcdb89b58bf to your computer and use it in GitHub Desktop.
using Gadfly
using Cairo
lin_vel = 0.3
ang_vel = -π/4
scale_setp = 0.2
time_step = 0.05
trajectories = Array(Float64, convert(Int32, 1/time_step),2,0)
for scale_val = 0.2:scale_step:1.0
lin_vel_scaled = lin_vel * scale_val
ang_vel_scaled = ang_vel * scale_val
pos_x = 0.0
pos_y = 0.0
pos_theta = 0.0
trajectory = Array(Float64, 0, 2)
for time_val = time_step:time_step:1.0
new_pos_x = pos_x + lin_vel_scaled * cos(pos_theta) * time_step;
new_pos_y = pos_y + lin_vel_scaled * sin(pos_theta) * time_step;
new_pos_theta = pos_theta + ang_vel_scaled * time_step;
trajectory = vcat(trajectory, [new_pos_x new_pos_y])
pos_x = new_pos_x
pos_y = new_pos_y
pos_theta = new_pos_theta
end
trajectories = cat(3, trajectories, trajectory)
end
draw(SVGJS("trajectories.svg", 30cm, 30cm), plot([layer(x=trajectories[:,2,i], y=trajectories[:,1,i], Geom.path()) for i in 1:size(trajectories,3)]..., Scale.x_continuous(minvalue=-1.5, maxvalue=1.5), Scale.y_continuous(minvalue=0.0, maxvalue=1.5)))
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment