How to add point on Cubric Bezier Curve? - wpf

In photoshop we can create bezier curve with pen tool,when we editing the completed curve,we can add point on the curve, in blend the same.
Now I have create a bezier path with wpf,how can I add point on it ,the special problem is I can't compute the control point of the new point.
Please help me, thank you.

what photoshop does is not "adding a control point", because that would raise the curve's order and change the curvature; instead, it splits the cubic curve into two cubic curves C1 and C2, with the endpoint of C1 and the startpoint of C2 are the same coordinate.
If WPF doesn't have curve splitting built into the API, then you might need to implement curve splitting yourself. It's pretty straight forward; for the DIY explanation, see http://pomax.github.io/bezierinfo/#splitting
The only challenge is to find the "t" value for the coordinate where you clicked, the simplest solution for that being to just generate the curve from t=0:1 in 1/100 or 1/1000 steps, and recording the x/y coordinate at each t value. That gives you a lookup table for instant lookup when you need to split the curve.

Related

How to find the surface control point for any given NURBS control point?

I have read through the "The Dirty Little Secrets of NURBS" article by Pilot3d (http://www.pilot3d.com/NurbSecrets.htm) and was intrigued by the surface located control points.
It does explain that each control has a respective surface point but it doesn't go as far as to explain how they are found and how moving a surface control point translates to the original control points. If I had to guess, you would find the surface control points by looking for the point on the surface when the contribution from a control point is at its maximum. Not sure about converting changes back to the original control points
I've somewhat figured this out just by thinking about it.
If you consider the general NURBS equation:
Lets say C(u_pi) is the point on the surface associated with a control point (how you decide this is technically arbitrary but it seems that the surface point closest to the control point will produce the best results) and that you would like to move it by a vector M.
So now you need to find the new P_i that takes into account this translation. If we take the general equation and subtract the contributions from all the control points except P_i (the control point we are interested in) then we get the following equation (assuming all weights are 1):
N_i,n * P_i + M = N_i,n * (P_i+P_idelta)
Then we can quite easily see that:
M = N_i,n*P_idelta
And hence you can control the shape of a NURBS surface by moving points on the surface rather than control points. The disadvantage of this method is that nearby surface points will also move but not at the rate. You can quite easily control the spread of the effect by the spreading the delta across several control points.

Control points in nurbs surfaces

So I've read a lot about nurbs recently and completely understand nurbs curves ( even wrote a small library for it ). But I'm having some problem with surfaces. I can see that I need two sets of control points. My problem is that what the difference between points in these two sets is?
Can anybody briefly explain it or give me some link that does?
I think my favorite way of understanding NURBS surfaces (if you already understand NURBS curves) is beads on a wire.
So, let's look at the much simpler example of a Bezier surface (I assume if you understand NURBS curves you understand Bezier curves).
A cubic Bezier curve has 4 control points. Imagine a Bezier curve which is just a smooth horizontal curve. You can compute any point on that curve given a parameter value (usually this is called t).. just plug t into the parametric equation of the curve, and a point is produced.
Now imagine you have 4 horizontal Bezier curves, each one is above the other. If you plug the same parameter value into all 4 curves, you get 4 points, one for each curve. Those are the beads on the wires. Let's call the parameter value for the horizontal curves 's'.
Take those 4 "bead" points and treat them as the control points of a vertical curve. Evaluate that curve at another parameter value (this one we'll call 't', like usual) and it will give you a point. That point is on the surface. Specifically, that's the point P(s,t).
So, given a 4x4 grid of control points, you can use beads on a wire to compute points on the surface. As s changes, the beads sweep out different curves along the wire.. the set of all those curves is the surface.
You can do the exact same thing with Nurbs curves.. you just need a knot vector for s, another knot vector for t, and a grid of control points.
For a NURBS surface, you dont need two sets of control points, you need a 2 dimensional grid or mesh of control points. This mesh will have n rows and m columns, and each point in the mesh will have an x, y and z co-ordinate as well as a w value, the NURBS weight for that point.

Triangulation of polygon

Im trying to triangulate a polygon for use in a 3d model. When i try using the ear method on a polygon with points as dotted below, i get triangles where the red lines are. Since there are no other points inside these triangles this is probably correct. But i want it to triangulate the area inside the black lines only. Anyone know of any algorithms that will do this?
There are many algorithms to triangulate a polygon that do not need partitioning into monotone polygons first. One is described in my textbook Computational Geometry in C, which has code associated with it that can be freely downloaded from that link (in C or in Java).
You must first have the points in order corresponding to a boundary traversal. My code assumes counterclockwise, but of course that is easy to change. See also the Wikipedia article. Perhaps that is your problem, that you don't have the boundary points consistently organized?
The usual approach would be to split your simple polygon into monotone polygon using trapezoid decomposition and then triangulate the monotone polygons.
The first part can be achieved with a sweep line algorithm. And speed-ups are possible with the right data-structure (e.g. doubly connected edge list). The best description of this, that I know, can be found in Computational Geometry. This and this also seem helpful.
Wikipedia suggest that you break the polygon up into monotone polygons. You check that the polygon is not concave by simply checking for all angles being less than 180 degrees - any corners which has a angle of over 180 is concave, and you need to break it at that corner.
If you can use C++, you can use CGAL and in particular the example given here that can triangulate a set of non-intersected polygons. This example works only if you already know the black segments.
You need to use the EarClipping algorithm, not the Delaunay. See the following white paper: http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf

How to find proper points to draw bezier curves in wpf

I'm writting small application to draw diagrams and I need to find points to draw bezier curve between two elements.
Is there any efficient and simple way to calculate bending points ??
To better visualize my problem please take a look at this picture
As You can see I have two rectangles which I want to connect with bezier curve. It is obvious that I have two anchor points, but how can I calculate correctly bending points so that this line would look like at the picture.
On each end of the curve imagine a line perpendicular to the border through the anchor point.
The curve points should be on that line. The farther away from the border these points lie the more vertical the center area of the curve is.
(I hope this is clear, it's at the limit of my english abilities)

Can I do a fillet curve in WPF?

My understanding of a fillet curve is that given three points where the middle point is associated with a radius, one can draw a curve from the two extreme points using a circle defined by the radius.
Is there support for this in WPF or would I have to implement it myself?
The answer is yes and no.
NO: There is no native function DrawFilletCurve(p1, p2, p3);
Yes: You can draw anything you want with Path. There is native support for cubic and quadratic Bezier curves.
You may also find something helpful in Live Geometry project, from MS ace Kirill Osenkov.

Resources