On Oct 11, 2004, at 4:09 AM, Dennis Ranke wrote:
> v = b*x + a*(1.0-x)
> ab.push v * (1 / Math.sqrt(v.inner_product(v)))

The Vector class has its own magnitude/length property called .r, so:

ab.push v * (1.0 / v.r )
would be slightly better.

Or, as I did:

# Extensions to the Vector class
class Vector
	# Returns a Vector whose length (<tt>.r</tt>) is 1.0
	def normalized
		self / self.r
	end

	# Divide the vector by a scalar
	# Scales the values in the Vector by 1.0 / n, and returns the new 
Vector
	def /( n )
		self * ( 1.0 / n )
	end

	# Modify the receiving vector to be of length (<tt>.r</tt>) 1.0
	def normalize!
		len = self.r
		self.scale_by!( 1/len )
	end

	# Modify the receiving vector, multiplying each component by the 
specified factor
	def scale_by!( scale_factor )
		@elements.collect!{ |e| e*scale_factor }
		self
	end
	
	# Modify the receiving vector, scaling it to be the specified length
	def r=(new_len)
		old_len = self.r
		self.scale_by!( new_len/old_len ) unless new_len==old_len
		self
	end	
end