How to build a smart bezier curve? - bezier

Demo Image : http://i.picpar.com/bzH.png
I want to build a smart bezier curve like this. There are 100 targets (grid) in the map. I know the source point (Rocket), and the target point (Grid). How to calculate two control points to build a beautiful bezier curve which can not across the blue map?

Find curve bounding box and then check if it is contained in blue map rectangle. If it will be outside move control points respectively.
Assuming that you are using cubic Bezier curve (4 control points) for first try You might set some default coordinates of curve control points:
P1(p0.x-10,p0.y+10)
P2(p3.x-10,p3.y+10)
I do not know what language/libraries You are using but it might have Rectangle.Contains(Bezier.BoundingBox) function which might make things easier.

Related

How to make edge sloped on a cylinder?

I'm beginner at 3D modelling and I'm making an office chair. Now I'm stuck at wheel area as I need a sloped edge cylinder for the base of the wheel.
Concept: The wheel is attached to a cylindrical base which is attached to the foot of the chair.
Current Situation: I draw foot of chair, made a circle on it and transformed into a cylinder. The end edge of the cylinder has no Face and I want to extrude the cylinder along one edge which will make a sloped area on the open side of area. That should look like this :
But I tried manythings to do, but failed. It's obvious as I said I'm beginner. Please help me do to this.
Note: I'm using blender 2.78
The shear tool will move your mesh the way you want. It doesn't create the geometry so first extrude E and then shear ⎈ Ctrl⎇ Alt⇧ ShiftS the extruded section. Also note that the shear tool always uses the viewport axis, so switch to front or side view to keep the movement in line with your object.
You could also extrude past the point you want and use the knife or bisect tool to cut the geometry at the angle you want.
I found the answer. This doesn't need complex techniques. I just did
Extrude > Merge > At the First.
That's it. Now I got the shape I wanted.

creating a bezier path from a simple image ios

I'd like to generate and draw some bezier paths based on an image in my app. The image will be really simple (black lines on a white background) such as the following:
Is there a method to process the image and create a bezier path based on the black lines? I'm completely lost here.
If you're wondering the reason for needing the image to be a bezier path, I'm going to be comparing the generated bezier path with another bezier path that the user draws (basically a picture-password that the user will have to draw).
If there's a better way to accomplish comparing an image to a bezier path, I'm all ears. Or, if bezier paths aren't the way to go, then let me know. Thanks!
Why not do it the other way around?
let the user draw the path
create an image from the drawn path using core graphics
compare both images with a framework like opencv
You cannot do this with bezier lines. Those are curves, while what you want is lines.
If you wanted to solve for control points though the solutions for this inverse problem
are infinite therfore you must set the number of control point that the bezier curve has.

Cubic Bezier from sample points

The sample points is taken from a flying machine in a fix sample rate (e,g 1s=25 frame), it contains the x,y,z position.
The requirement is to import the point lists and edit the curve, then export it to a new point lists.
I want to use the Cubic Bezier curve to display the points, the problem is :
The flying path is arbitrary, can it always be drawn in Bezier curve?
How to confirm the vertex and control points?
The reason of vertex and control point is for editing, i want to drag the control point to modify the curve.
Am new for this field, any suggestion or sample code is appreciated. :)
Cubic Bezier spline won't fit to an arbitrary digitized curve. If Cubic Bezier spline approximate your curve with unacceptable square error, there are two options:
Split original curve into segments (for example, where curve bends) and then fit segments with Cubic Bezier splines. There is a description of an algorithm for automatically fitting digitized curves
Use higher order Bezier splines than cubic, which can fit any continuous smooth curve.
This will result in iterative process to find Bezier spline of minimum order fitting the curve with an acceptable error.

How to draw a Bezier Path passing through touch location if control point is unknown in iPhone?

I have two fixed points, P1 & P2. On touch, How can i draw a Bezier Path passing through P1, Touch point and P2?
In other words, Is there any way to find out the location of control point if we know the touch point location?
I think you want Schneider's bezier curve-fitting algorithm. It takes a bunch of points and fits a bezier curve through them.
http://iut-arles.univ-provence.fr/web/romain-raffin/sites/romain-raffin/IMG/pdf/PSchndeider_An_Algorithm_for_automatically_fitting_digitized_curves.pdf

Drag a bezier curve to edit it

You will understand what I mean if you use graphic editing programs like Gimp or Photoshop. To edit a curve on those programs (which probably is Bezier Curve), we can click on the curve, drag the mouse and the curve is changed accordingly. I suspect all the things behind this mechanism are concerned with vectors, but I couldn't find any document mentioning how to do it. Could anybody tell me how I can do that? Thank you very much.
[edit] What I meant was to select-the-curve itself to change (edit) it (click on the curve, and drag the curve to edit it). In the usual way, we select the control points to change the curve. I know to change the curve, I need to edit the control points, but how do I interpret a change on a curve into a change into a change to control points?
There are a number of ways of accomplishing what you're seeing, depending on how you'd like it to behave. I'll explain some of the simpler methods of modifying a Bezier curve via point on curve manipulation.
The first thing to do is figure out the parameter value (t) where the user clicked on the curve. This is generally going to be an approximation. If you're doing pixel or sub-pixel rendering of the Bezier, then just record for every pixel what the t value was and use that. If you're tessellating into line segments, see which line segment is closest, find the t values of the two end points, and lerp the t value according to the distance along the line.
Once you have the t value, you can plug it into the Bezier curve equation. You'll end up with something of the form:
P = k0*P0 + k1*P1 + k2*P2 + k3*P3
where P is the point on the curve, P0, P1, P2, and P3 are the input control points, and k0, k1, k2, and k3 are constants for a given t. I'll call the k values 'contributions', or more specifically the contributions of control points to the point on the curve P(t). A nice property to remember is that k0+k1+k2+k3 = 1.
So, let's say you have a vector V = P' - P, where P' is the new position and P is the original position. We need to move some of the control points to get P' where it needs to go, but we have some flexibility about which of the control points we want to move. Any point with non-zero contribution can be used, or some combination.
Let's say the user clicks on the curve at t=0. In this case, only k0 is non-zero, so
P0 := P0 + V
will produce the correct result. This can also be written as
P0 := P0 + k0 * V
In the general case where all of the contributions are nonzero, you can apply the same transformation to each of the points, which will have the effect of a very smooth, spread-out deformation.
Another option is to simply move the control point with the maximum contribution the entire distance. I think the equation to use would be something like
Pmax := Pmax + 1/kmax * V
but either way it boils down to looking at the contributions at a given t value, and moving the control points so the new point lies in the desired location.
This approach is fairly general, and works for NURBS and most other splines, even surfaces. There is another method that's fairly common that uses Greville Abscissae, which pins as many points as possible, but in my experience it's too easy to get oscillation.
EDIT - In response to your question edit
In order to be able to select the curve itself to move the control points, I would suggest that Bezier curves are definitely not the way forward - you would have to solve the equation in reverse in order to find the right control point locations. You would also find that in some cases it's actually not possible to move the control points to make the curve go where you want.
If you were using B-Splines, then you could simply insert a new control point at the point on the curve closest to where the user has clicked, and then move the new control point. So, effectively, you'd be adding a new control point.
Original text
Assuming you already have an implementation of a bezier curve which, given a set of control points (typically three for Bezier but can be as many as you want) can produce a set of points to be joined with lines on the display device (typically you use the 0 >= u <= 1 parametric equation), then this is easy.
Your control points determine where the curve goes, so you simply need to implement selection feedback and drag/drop on those control points.
If you're looking for exact point matching, however, bezier curves are not ideal since they only pass through the first and last control points. And the more points you add to the curve, the less accurate they become.
B-Splines would be better, and variations of these are what you actually see in photoshop et al.
Dragging simply changes the control points of the Bezier curve, and the curve is recalculated accordingly. See Wikipedia for a good explanation on how they work.
Please clarify what you wish to do? Do you want to edit bezier curves in an application? Are you interested in the general maths behind it?
Normally you manipulate the control points that is used to generate the bezier curve.
OK, so let's assume that you have to use Bezier curves because you're using a rendering library that has them as a primitive. If you're absolutely married to the idea of using control points on the curve itself, you can just interpolate control points using the method outlined here: How to find control points for a BezierSegment given Start, End, and 2 Intersection Pts in C# - AKA Cubic Bezier 4-point Interpolation
In other words, for every set of 4 points on the curve, you would run the above algorithm and get the 4 control points needed to draw the cubic Bezier.
See github.com/bootchk/freehandTool for object models
A user drags. Project the drag onto nearest control point or arm between control points. Interpret the drag as rotation and or translation (transform) of said nearest control points. Note plural: nearest may be coincident control points( ends) of two segments, or control points of arm of bezier segment.