Smoothing a Bezier Curve to a moving endpoint - unreal-engine4

I am trying to do something tricky with Bezier Curves.
What I've got:
Basically, I want to move the endpoint/destination while traversing at a constant speed. The example image I've provided is a Ball traversing my Bezier Curve.
The constant speed aspect is working. However, as soon as I move the destination, the ball snaps to the newly-updating Bezier Curve. As a result, the ball appears to move faster, going against what I'm trying to achieve.
I'm still new to using Bezier Curves, so I'm wondering if I'm missing some sort of additional calculation when the target moves.
I'm doing this all with the Blueprint system in Unreal Engine 4.
Does anyone have any suggestions? Thanks 🙂

After a bit of experimentation, I came up with a solution that works for me:
Check if the Bezier Curve has changed (I do this by checking if the target has moved)
If the Bezier Curve has changed, set the ball to travel towards the would-be point on the new Bezier Curve. We get this point by plotting the same distance along the new Bezier Curve.
As a result, the ball now maintains a constant speed without snapping, and will attempt to play catch-up if the Bezier Curve changes.

Related

How can you create this shape in Swift?

I tried to create this very unique shape in swift a long time ago but failed. My goal is to draw a shape like in this image here (I mean the darker shape in that image).
How can you create such a unique shape in Swift?
As Alexander says, it looks like that shape would be pretty easy to create using Bezier curves.
I'd suggest opening that image in a program like Photoshop that offers a Bezier path drawing tool and trying to recreate it there. Once you have the control points that get you the shape you are after, you can write down their coordinates and recreate them using a UIBezierPath in iOS.
A cubic bezier path has 2 end points and 2 middle control points. The curve moves from the starting point to the ending point, and gets pulled towards the first middle control point first, and then pulled towards the second control point. You can create a wide variety of curves that have 2 "humps" in them with a single Bezier curve, and you can chain multiple Bezier curves together to create more complex shapes. If you arrange the control points for connecting Bezier curves correctly you can get curves that transition smoothly from one to the next. With a different arrangement of the control points between Bezier curves, you can create sharp corners between curves.
I suggest you google Bezier curves, and do some experimenting.
I'm not particularly good with the path tool in Photoshop, but I got pretty close with a few minutes tinkering. here is a screen-shot:

How to approximate distance traveled on Bezier Spline

I'm working on a game that mixes 3D and 2D gameplay. For 2D, the character can move along a bezier spline, side-scroller style. He is not, however, entirely stuck to the path as he can jump and do air dashes. That said, a problem comes up when trying to get the current position and tangent to use on the spline.
If the movement was entirely on the ground, simply adding the speed to the distance traveled would work however it is possible to skip entire parts of the spline thus rendering the whole method useless.
In the picture below, if the character wall jumps his way through to the upper platform he can jump off and skip the whole pipe segment thus traveling a shorter distance.
Of course, I tried just using the closest point on the spline but that's not reliable in figure 8 splines or this same situation even.
I would be so grateful if anyone could point me in the right direction.
(note: to keep the player aligned to the spline I get the position on the spline by distance and lerp his position there while keeping his Y untouched )

shoulder detection on a segmented image

As an input I have a segmented image of the upper body, I'm trying to detect shoulders from this image.
I minimized the region by a threshold calculated by simple known ratios between head size and shoulder width.
Now I have the shoulders region, performed edge detection on it.
Now I need to find the points of shoulders.
is there a fast way to detect the shoulder curves ?
I'm using Matlab.
This is my input image :
Bezier Curve is just a mathematical description of a curve, (linear interpolation, using control points).
It is not a curvetracer.
If you need bezier curve descriptions, you would need to do a best fit between a bezier curve model, and the data. Before you get started, you should probably play around with bezier curves, to get a feeling of how they operate.
See here: http://www.mathworks.com/matlabcentral/fileexchange/33828-generalised-bezier-curve-matlab-code
for a Bezier Curve render, in matlab.
It displays the bezier curve, when you provide some control points.
There is a few methods to actually fit a bezier curve to a set of data, here is one for matlab (using the least squares method).
http://www.mathworks.com/matlabcentral/fileexchange/15542-cubic-bezier-least-square-fitting
It will some times work nicely, and sometimes fail miserably, this is due to the least squares method, and the uniform parameterization used. It should work OK for your shoulder problem.
you need to extract the edge data, as data points, but that should be trivial

How to find normals to an edge in an image

I am doing some work related to eye images.
I did edge detection to it. The edge is like a curve and not continuous. I have to assume it to be continuous and find normals to that curve. How do I find the normals to it using MATLAB?
you can see the image below.
I want to find the normals to the upper curve.
I hope that I was clear enough.
Even though it seems unintuitive, the edge direction at every pixel is a pretty good estimate of the normal. This would be the simplest solution, because it doesn't involve any curve fitting.
In MATLAB, you can find pixel-wise edge directions using the Sobel filter:
[BW,thresh,gv,gh] = edge(I,'sobel');
edgeDir = atan2(gv, gh);
This gives you the edge directions as angles in radians.
You may want to consider curve fitting (MSE based or some other criteria) to the data. I believe a second order will do good for the upper curve, and once you have a model you can can calculate the tangent and normal at each point.
As Zaphod recommended the normal is perpendicular to the edge. You don't need to do curve fitting, you can use back projection to identify the focal point of the curve.
Start at each edge point along the curve and draw a line from curve in the direction of the normal. Draw the line by incrementing the value of each pixel the line passes through. Once you do this for all the edges you would hope to find two pixels with higher values then the rest, one for each of your curves. You should then know by there locations which is the focal point for each curve.

How to draw a smooth curve in iphone while I can only get all the points in runtime?

I am learning quartz for ios development. And I want to write a chart class to draw smooth curve, and I can only know how many points there are in runtime. Please give me some solutions to achieve this.
Now I use UIBeizerPath, but I cannot use the control point well, there's very obvious corner in it.
Thanks and best regards.
To work out control points in Bezier curves draw a imaginary line from the actual point which is at a tangent to the curve you wish to create.
Think about missing a bend when driving a car. Car goes straight ahead while curve does its curve thing. The distance of the control point (car) from the actual point determines the amount of curve.
This answer has the raw principles as an answer to your question
how can i trace the finger movement on touch for drawing smooth curves?
But try researching C and C++ code for bezier curve smoothing and interpolation if you dont want to bake it yourself. You can use any C or C++ in a Objective C project.
Good Luck