How to write a Bezier curved path on the fly with one fixed point and one changing - uibezierpath

If I have an object performing this CAKeyframe Animation path (it is just an oval shape in the upper region of an iphone..
UIBezierPath *trackPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(20, 100, 280, 150)];
Now imagine that at anytime during this paths travels I want to create a smooth path from its current position at a point in time and some point at the bottom of the screen.
By the way I am assuming that once I have a path I can stop the current CAKeyframeAnimation and add this path to a new CAKeyframe animation, but maybe if this is incorrect you can give me pointers here as well please.

So I said to myself "Self.....it looks like you are going to have to answer this one yourself as nobody even wants to edit it or say that it is a duplicate......"
So I was hoping for some easier or ready made way to do this. From what I have found there is no easy way. It seems the steps are going to be;
get the current position of the animated layer
calculate yourself with all your own code a nice smooth curve
add this path to an animation and animate it.
As for the calculation of a Bezier Curve I am still looking to find some class or code where points can be plugged into it and the two control points are produced for the UIBezier class to produce a curve.
In my case I am going to only animate "out" of my above questioned shape a determined points and thus have ready made smooth curves which I have prepared.
Animating a smooth exit from an oval at any point is very complicated and In my case just not worth it. So I have not done that.

Related

2D space organic projection

I'm currently working on a glsl shader (EDIT : I'm starting to think that a shader isn't necessarily the best solution and as I'm doing this in processing, I can consider a vectorial solution too) supposed to render something like this but filling the entire 2D space (or at least a larger surface):
To do so, I want to map the repeating patterns on the general leaves shapes that you can see on the top of the sketch below.
My problem is this mapping part : is it possible to find a function that project XY coordinates on the screen to another position in such a way that I can map my patterns the way I want? The leaves must have some kind of UV coordinates inside them (to be able to apply the repeating pattern) and the transformation must be a conformal map because otherwise, there would be some distortions in the pattern.
I've tried several lines of thought but I haven't managed to get the final result :
recursion :
the idea is to first cut the plane in stripes, then cut the stripes in leaves shapes that touch the top and the bottom of the stripes (because that's easier) and finally recursively cut the leaves in halves until the result looks more random. as long as the borders of the stripe aren't on the screen, it shouldn't be too noticeable. The biggest difficulty here is to avoid the distortion.
voronoi :
it may be possible to find a distance function guided by a vector field such that the Voronoi diagram looks more like what I'm looking for. However I don't think it will be possible to have the UV mapping I want. If it's the case, a good approximation woult do the trick, the result doesn't need to be exact as long as it isn't too noticable.
distortion :
it could also be possible to find a more direct way to do this projection. While desperately looking for a solution, I came across the fact that a continuous complex function is a conform map but I haven't managed to go any further.
Finaly, there may be another solution I haven't thought about and I would be glad if someone gave me a complete solution or just a new idea I haven't tried yet.

Eliptic looking graph

What options should I use for making my graph looking like an Elipse ? I was messing with the hierarchical option under the layout module, but I've not gotten nowhere near my desired shape.
My graph is left to right, left node group connects to middle one, and middle one connects to the right one. It can be perceived as this image below.
Can someone point me in the right direction ? Thanks for your expertise
As for the elliptic shape around the nodes and edges, you can either set a background image to your graph area or create a node of large size (but this way you may have troubles with node repulsion, though). Unfortunately, there's no way to make sure that all the nodes will always be inside the ellipse (unless you access the vis' canvas and deal with it on low level or do some other hackery).
Also AFAIK it is impossible to create those wavy edges, but for those rounded ones you may want to use repulsion physics instead of barnesHut. See also physicsConfiguration example.

How tell if a point is within a polygon for texture

This seems to be a rather asked question - (hear me out first! :)
I've created a polygon with perlin noise, and it looks like this:
I need to generate a texture from this array of points. (I'm using Monogame/XNA, but I assume this question is somewhat agnostic).
Anyway, researching this problem tells me that many people use raycasting to determine how many times a line crosses over the polygon shape (If once, it's inside. twice or zero times, it's outside). This makes sense, but I wonder if there is a better way, given that I have all of the points.
Doing a small raycast for every pixel I want to fill in seems excessive - is this the only/best way?
If I have a small 500px square image I need to fill in, I'll need to do a raycast for 250,000 individual pixels, which seems like an awful lot.
If you want to do this for every pixel, you can use a sweeping line:
Start from the topmost coordinate and examine a horizontal ray from left to right. Calculate all intersections with the polygon and sort them by their x-coordinate. Then iterate all pixels on the line and remember if you are in or out. Whenever you encounter an intersection, switch to the other side. If some pixel is in, set the texture. If not, ignore it. Do this from top to bottom for every possible horizontal line.
The intersection calculation could be enhanced in several ways. E.g. by using an acceleration data structure like a grid, quadtree, etc. or by examining the intersecting or touching edges of the polygon before. Then, when you sweep the line, you will already know, which edges will cause an intersection.

How to Minimize the saved points from drawn points using free-flow drawing tool

Currently I'm using "Douglas Peucker" algorithm.
My problem is that when I'm drawing,the previously drawn lines are also changing which of course not realistic. Is there other alternative algorithm to minimize the saved points but not altering the previous drawn points or other way to alter "Douglas Peucker" to fit my need?
Give your pencil drawing tool 2 optional methods for drawing:
Draw a new point on the path using mousemove (which is your current freeform method). This option will let the user add many points which will allow them to be very detailed in their drawing.
Draw a new point on the path only upon mousedown. This option simply connects the previous point on the path to the newly clicked point. This option will let the user add just a few very straight lines which will allow them to outline figures with long running straight edges.
If you are concerned about the freeform path changing while the user is drawing you can apply the simplifying algorithm just once after they have stopped moving the mouse for 1 second.
If you specify the Douglas-Peucker algorithm use a high bias for accuracy then the simplified path will remain quite true to the unsimplified path.
BTW, if you want to draw splines through your points then check out this nice previous post: how to draw smooth curve through N points using javascript HTML5 canvas?

Where can I find information on line growing algorithms?

I'm doing some image processing, and I need to find some information on line growing algorithms - not sure if I'm using the right terminology here, so please call me out on this is needs be.
Imagine my input image is simply a circle on a black background. I'd basically like extract the coordinates, so that I may draw this circle elsewhere based on the coordinates.
Note: I am already using edge detection image filters, but I thought it best to explain with a simple example.
Basically what I'm looking to do is detect lines in an image, and store the result in a data type where by I have say a class called Line, and various different Point objects (containing X/Y coordinates).
class Line
{
Point points[];
}
class Point
{
int X, Y;
}
And this is how I'd like to use it...
Line line;
for each pixel in image
{
if pixel should be added to line
{
add pixel coordinates to line;
}
}
I have no idea how to approach this as you can probably establish, so pointers to any subject matter would be greatly appreciated.
I'm not sure if I'm interpreting you right, but the standard way is to use a Hough transform. It's a two step process:
From the given image, determine whether each pixel is an edge pixel (this process creates a new "binary" image). A standard way to do this is Canny edge-detection.
Using the binary image of edge pixels, apply the Hough transform. The basic idea is: for each edge pixel, compute all lines through it, and then take the lines that went through the most edge pixels.
Edit: apparently you're looking for the boundary. Here's how you do that.
Recall that the Canny edge detector actually gives you a gradient also (not just the magnitude). So if you pick an edge pixel and follow along (or against) that vector, you'll find the next edge pixel. Keep going until you don't hit an edge pixel anymore, and there's your boundary.
What you are talking about is not an easy problem! I have found that this website is very helpful in image processing: http://homepages.inf.ed.ac.uk/rbf/HIPR2/wksheets.htm
One thing to try is the Hough Transform, which detects shapes in an image. Mind you, it's not easy to figure out.
For edge detection, the best is Canny edge detection, also a non-trivial task to implement.
Assuming the following is true:
Your image contains a single shape on a background
You can determine which pixels are background and which pixels are the shape
You only want to grab the boundary of the outside of the shape (this excludes donut-like shapes where you want to trace the inside circle)
You can use a contour tracing algorithm such as the Moore-neighbour algorithm.
Steps:
Find an initial boundary pixel. To do this, start from the bottom-left corner of the image, travel all the way up and if you reach the top, start over at the bottom moving right one pixel and repeat, until you find a shape pixel. Make sure you keep track of the location of the pixel that you were at before you found the shape pixel.
Find the next boundary pixel. Travel clockwise around the last visited boundary pixel, starting from the background pixel you last visited before finding the current boundary pixel.
Repeat step 2 until you revisit first boundary pixel. Once you visit the first boundary pixel a second time, you've traced the entire boundary of the shape and can stop.
You could take a look at http://processing.org/ the project was created to teach the fundamentals of computer programming within a visual context. There is the language, based on java, and an IDE to make 'sketches' in. It is a very good package to quickly work with visual objects and has good examples of things like edge detection that would be useful to you.
Just to echo the answers above you want to do edge detection and Hough transform.
Note that a Hough transform for a circle is slightly tricky (you are solving for 3 parameters, x,y,radius) you might want to just use a library like openCV

Resources