Difference between revisions of "BezierCurve:evaluate"

(Function was renamed)
(Undo revision 27963 by Darkfrei (talk). Mention the control point requirement in the description instead.)
(Tag: Undo)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{newin|[[0.9.0]]|090|type=function}}
 
{{newin|[[0.9.0]]|090|type=function}}
Evaluate Bézier curve at parameter t. The parameter must be between 0 and 1 (inclusive).
+
Evaluate Bézier curve at parameter t. The parameter must be between 0 and 1 (inclusive) and there must be at least two control points for the curve.
  
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.
+
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 ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
x,y = BezierCurve:evaluate(t)
+
x, y = BezierCurve:evaluate( t )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|number|t|Where to evaluate the curve.}}
+
{{param|number|t|Where to evaluate the curve. Must be between 0 and 1.}}
 
=== Returns ===
 
=== Returns ===
 
{{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.}}
 +
== Examples ==
 +
 +
=== Make a circle follow a curve ===
 +
<source lang="lua">
 +
local controlPoints = {125,125, 125,225, 175,125, 225,125}
 +
local curve        = love.math.newBezierCurve(controlPoints)
 +
 +
function love.draw()
 +
local time    = love.timer.getTime()
 +
local loopTime = 4
 +
local t        = (time / loopTime) % 1
 +
local x, y    = curve:evaluate(t)
 +
 +
love.graphics.circle("fill", x, y, 8)
 +
love.graphics.line(curve:render())
 +
end
 +
</source>
 +
 
== See Also ==
 
== See Also ==
 
* [[parent::BezierCurve]]
 
* [[parent::BezierCurve]]
 
* [[BezierCurve:render]]
 
* [[BezierCurve:render]]
 
* [[love.math]]
 
* [[love.math]]
 +
* [https://love2d.org/forums/viewtopic.php?f=4&t=83825 Bezier Curves, how to trace a line? - LÖVE forum]
 +
 
[[Category:Functions]]
 
[[Category:Functions]]
 
{{#set:Description=Evaluate Bézier curve at parameter t.}}
 
{{#set:Description=Evaluate Bézier curve at parameter t.}}
 +
 
== Other Languages ==
 
== Other Languages ==
 
{{i18n|BezierCurve:evaluate}}
 
{{i18n|BezierCurve:evaluate}}

Latest revision as of 17:07, 14 August 2022

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) and there must be at least two control points for the curve.

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. Must be between 0 and 1.

Returns

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

Examples

Make a circle follow a curve

local controlPoints = {125,125, 125,225, 175,125, 225,125}
local curve         = love.math.newBezierCurve(controlPoints)

function love.draw()
	local time     = love.timer.getTime()
	local loopTime = 4
	local t        = (time / loopTime) % 1
	local x, y     = curve:evaluate(t)

	love.graphics.circle("fill", x, y, 8)
	love.graphics.line(curve:render())
end

See Also


Other Languages