I am trying to make a curve function that returns a set of positions. I only have 2 points, how do i make a smooth curve out of these 2 point?
I’ve looked at Bezier Curves but it takes at least 3 points to get a curve.
I am trying to make a curve function that returns a set of positions. I only have 2 points, how do i make a smooth curve out of these 2 point?
I’ve looked at Bezier Curves but it takes at least 3 points to get a curve.
How is the function supposed to know what kind of curve you want?
pretty sure you would always need a third point to tell how intense the curve is going to be if its 2 points then its just a line m8.
By giving the three points to a bezier curve function?
If you mean “how do I calculate the third point” then it depends on where you want the third point to be:
What direction do you want the L curve? How smooth should it be? etc…
I learned a lot from this module to create tween bezier curves with 3 points dinamycally, to make a part travel all the points
Bezier Curve Creator
You can generate a right angle triangle between the points, but then still you don’t know which side…
test the 3, I made the arguments easier to read
Lerp
local function Lerp(Start, End, Time)
return Start + (End - Start) * Time
end
local Start = Vector2.new(0, 0) -- top left
local End = Vector2.new(1, 1) -- bottom right
for Time=0, 1, 0.01 do
print(Lerp(Start, End, Time))
end
Quadratic
local function QuadraticBezier(Time, Start, Middle, End)
return (1 - Time)^2 * Start + 2 * (1 - Time) * Time * Middle + Time^2 * End
end
local Start = Vector2.new(0, 0) -- top left
local Middle = Vector2.new(1, 0) -- top right I think
local End = Vector2.new(1, 1) -- bottom right
for Time=0, 1, 0.01 do
print(QuadraticBezier(Time, Start, Middle, End))
end
Cubic
local function CubicBezier(Time, Start, Middle1, Middle2, End)
return (1 - Time)^3*Start + 3*(1 - Time)^2*Time*Middle1 + 3*(1 - Time)*Time^2*Middle2 + Time^3*End
end
local Start = Vector2.new(0, 0) -- top left
local Middle1 = Vector2.new(1, 0) -- top right
local Middle2 = Vector2.new(0, 1) -- bottom left
local End = Vector2.new(1, 1) -- bottom right
for Time=0, 1, 0.01 do
print(CubicBezier(Time, Start, Middle1, Middle2, End))
end
You must have at least 1 extra point.
What you linked needs more than 2 points.
What you posted also needs more than 2 points (except for the lerp but that isn’t a curve).
Also Artzified’s link
has the code you posted
This has already been said.
Please read the post and it’s replies to see whether your otherwise useful replies are needed.
Here’s some pseudo code to generate the third point
Depending on which point you calculate the angle from and whether you add or subtract 90° you can choose which of the 2 red points you want.
Thats what I said… 3 points… I support that having 3 points its needed…
3 points and even more its helpful
The link you posted is helpful, but it isn’t what Artzified asked for, he already has code to generate a bezier curve
He just needs an alternative to bezier curves that doesn’t need 3 points (doesn’t exist), or a way to generate the third point.
yeah… if using less than 3 points its not possible, and not knowing how to generate the point 3, I just provided a module to check to understand the using the 3 points, documentation never harms… ¬¬
i’m having trouble getting the angle. is this correct?
local angle = (p1 - centerPoint).Unit:Dot(p2)
which one?
I meant something more like this
local p1Offset = p1 - centerPoint
local angle = math.atan2(p1Offset.Y, p1Offset.X)
+ math.rad(90) -- add the 90° right away, no need to wait
Then generate the new point like so
local radius = diameter / 2
local thirdPoint = Vector2.new( math.cos(angle) * radius, math.sin(angle) * radius )
It doesn’t seem to work when i visualize it in 3d space
local diameter = (p1.Position-p2.Position).Magnitude
local centerPoint = (p1.Position-p2.Position) / 2
local offset = p1.Position - centerPoint
local angle = math.atan2(offset.Y, offset.X) + math.rad(90)
local radius = diameter/2
local thirdPoint = Vector3.new(math.cos(angle) * radius, math.sin(angle) * radius)
No in 3d it wouldn’t work, because then you have an infinite amount of red points (the red circle)
What do the 2 points represent and why do you need an L shaped angle between them?