Let's say I have Quadratic Bezier Curve like the black one.
I want to create a prallel Bezier Curve like red one.
How can I do that?
My Approach:
Let's draw using quadraticBezierTo(controlePoint, endingPoint). Assume startingPoint=(0,0)
2.Using equation of quadratic bezier curve, let's find an array of points
Let's draw these new points offsetting them a few pixel horizontally in left side.
What could be the better way of doing it?
Related
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:
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
I would like to draw an arbitrary curve on Matlab with my mouse, say a heart or pikachu. How exactly can I do that? Also, I would like to obtain data points from that curve such if I use scatter, the data points look like they form the curve I drew. How can I do that?
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.
I have a task - draw smooth curve
input: set of points (they added in realtime)
current solution: I use each 4 points to draw qubic Bezier curve (1 - strart, 2 and 3rd - control points, 4- end). End point of each curve is start point for the next one.
problem: at the curves connection I often have "fracture" (angle)
Can you tell me, how to connect my points more smooth?
Thanks!
Here is few references which can help you:
Draw a Smooth Curve through a Set of 2D Points with Bezier Primitives
Curve fitting
Line Smoothing and point-weeding