Difference between revisions of "BezierCurve:evaluate"

m (See Also: forum linked.)
Line 14: Line 14:
 
{{param|number|x|x coordinate of the curve at parameter t.}}
 
{{param|number|x|x coordinate of the curve at parameter t.}}
 
{{param|number|y|y coordinate of the curve at parameter t.}}
 
{{param|number|y|y coordinate of the curve at parameter t.}}
 +
=== Example ===
 +
Get list of coordinate pairs:
 +
<source lang="lua">
 +
local BezierCurve = love.math.newBezierCurve({25,25,75,50,125,25})
 +
local list = {}
 +
local subdivisions = 2^3
 +
local line = {}
 +
for i = 0, subdivisions do
 +
local t = i/subdivisions
 +
print (t)
 +
local x, y = BezierCurve:evaluate(t)
 +
table.insert (line, x)
 +
table.insert (line, y)
 +
end
 +
love.graphics.line(line)
 +
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::BezierCurve]]
 
* [[parent::BezierCurve]]

Revision as of 13:53, 21 November 2021

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Evaluate Bézier curve at parameter t. The parameter must be between 0 and 1 (inclusive).

This function can be used to move objects along paths or tween parameters. However it should not be used to render the curve, see BezierCurve:render for that purpose.

Function

Synopsis

x,y = BezierCurve:evaluate(t)

Arguments

number t
Where to evaluate the curve.

Returns

number x
x coordinate of the curve at parameter t.
number y
y coordinate of the curve at parameter t.

Example

Get list of coordinate pairs:

local BezierCurve = love.math.newBezierCurve({25,25,75,50,125,25})
local list = {}
local subdivisions = 2^3
local line = {}
for i = 0, subdivisions do
	local t = i/subdivisions
	print (t)
	local x, y = BezierCurve:evaluate(t)
	table.insert (line, x)
	table.insert (line, y)
end
love.graphics.line(line)

See Also


Other Languages