class DemCurves::CubicBezier

Public Class Methods

new(start_point, start_handle, end_handle, end_point) click to toggle source
Calls superclass method DemCurves::PathElement::new
# File lib/core/path-element.rb, line 49
def initialize(start_point, start_handle, end_handle, end_point)
  super({
    :start => start_point, 
    :start_handle => start_handle, 
    :end_handle => end_handle, 
    :end => end_point})
end

Public Instance Methods

generate(t_freq=32) click to toggle source
# File lib/core/path-element.rb, line 57
def generate(t_freq=32)
  step = 1.0 / t_freq
  @path_points = (0..t_freq).collect {|i| interpolate(step * i)}
end
get_guides() click to toggle source
# File lib/core/path-element.rb, line 69
def get_guides
  # this will be removed soon.
  return [[self[:start].loc, self[:start_handle].loc], [self[:end_handle].loc, self[:end].loc]]
end
interpolate(t) click to toggle source
# File lib/core/path-element.rb, line 62
def interpolate(t)
  # http://mathworld.wolfram.com/BezierCurve.html
  (0..3).inject(Vector[0, 0]) do |mem, i|
    mem += @control_points.values[i].loc.clone * bernstein_basis(i, 3, t)
  end
end