de Casteljau algorithm Objective-C - ios

I'm not very mathematically inclined, so it would be great if someone could provide me a code example of de Casteljau algorithm in Objective-C. I'm attempting to calculate the points along a curve between a start point and an end point. Basically what I'm trying to do is create view that looks similar to a UIActivityIndicatorView. I would just use images, but it needs to be dynamic and have any number of ticks. My plan was to draw the view in four quadrants, top-left, top-right, bottom-right, bottom-left. I was basically just going to draw one quadrant and then just create that view 3 more times and apply transforms to them to complete the circle.
I would appreciate any help, thanks!

Related

How to make a bowling pin like structure in webgl

I want a structure like this:
I have made a cylinder and placed a smaller cylinder on top of it.
For the base cylinder I was thinking of smoothly increasing the x-coordinate till the half of max(y co-ordinate) as y increases and then smoothly decreasing x for y > half(max(y co-ordinate)) as y increases.
But rotating the shape distorts it.
Is there a way to make a shape like this using basic webgl and not any advanced libraries such as Three.js.
As I mentioned in the comments the most common way to make shapes for 3D is to use a 3d modeling package like Blender or Maya or 3D Studio Max or DAZ or Cinema4D etc...
If you really want to do it in code though, well the most obvious idea is to make a function that makes a cylinder then pinch it in the right places using a sine wave. That probably won't get you want you want though because you'll need to make the cylinder very high res (lots of vertices) in order for the top round part to become smooth.
The way a 3D modeling package would likely do this is you'd use a spline to create the 2D outline of the bowling pin. You'd then "lathe" or rotate the spline around the center to generate vertices. The modeling package would have settings for how many points to place along the spline and how many points around to generate. It would also have settings to decide whether to place points at equal distances along the spline or to do some kind of curve fitting / error accumulation to figure out where more points are needed and where less points are needed.
I ended up being curious about this so I wrote an article about it

What time the line turn? Image processing

I'm using LeapMotion with Processing.
I want to draw a triangle with my hands , and make these line straight .
and my data is all 2D point(x,y) per frame
The triangle what I draw absolutly not straight.
So first I use "linear Regression" to draw a straight line.
and my question is
What time the user turn when they draw a triangle?
(my opinion is to us "angle extremes" to detect what time its turn.)
Is there some image processing technology to use?
If you have the parametrized model of all 3 lines, what you need to do is find for each pair of lines the point that is the least distance from the two lines.
That is your corner.
For the lines, one linear regression would probably not do. Perhaps do some ransac to find the lines and K-means to cluster the points to their lines.

How to create sprite surface like in "cham cham"

My question maybe a bit too broad but i am going for the concept. How can i create surface as they did in "Cham Cham" app
https://itunes.apple.com/il/app/cham-cham/id760567889?mt=8.
I got most of the stuff done in the app but the surface change with user touch is quite different. You can change its altitude and it grows and shrinks. How this can be done using sprite kit what is the concept behind that can anyone there explain it a bit.
Thanks
Here comes the answer from Cham Cham developers :)
Let me split the explanation into different parts:
Note: As the project started quite a while ago, it is implemented using pure OpenGL. The SpiteKit implementation might differ, but you just need to map the idea over to it.
Defining the ground
The ground is represented by a set of points, which are interpolated over using Hermite Spline. Basically, the game uses a bunch of points defining the surface, and a set of points between each control one, like the below:
The red dots are control points, and eveyrthing in between is computed used the metioned Hermite interpolation. The green points in the middle have nothing to do with it, but make the whole thing look like boobs :)
You can choose an arbitrary amount of steps to make your boobs look as smooth as possible, but this is more to do with performance.
Controlling the shape
All you need to do is to allow the user to move the control points (or some of them, like in Cham Cham; you can define which range every point could move in etc). Recomputing the interpolated values will yield you an changed shape, which remains smooth at all times (given you have picked enough intermediate points).
Texturing the thing
Again, it is up to you how would you apply the texture. In Cham Cham, we use one big texture to hold the background image and recompute the texture coordinates at every shape change. You could try a more sophisticated algorithm, like squeezing the texture or whatever you found appropriate.
As for the surface texture (the one that covers the ground – grass, ice, sand etc) – you can just use the thing called Triangle Strips, with "bottom" vertices sitting at every interpolated point of the surface and "top" vertices raised over (by offsetting them against "bottom" ones in the direction of the normal to that point).
Rendering it
The easiest way is to utilize some tesselation library, like libtess. What it will do it covert you boundary line (composed of interpolated points) into a set of triangles. It will preserve texture coordinates, so that you can just feed these triangles to the renderer.
SpriteKit note
Unfortunately, I am not really familiar with SpriteKit engine, so cannot guarantee you will be able to copy the idea over one-to-one, but please feel free to comment on the challenging aspects of the implementation and I will try to help.

Detecting multiple shapes in a picture and calculate the middle

This question can be answered with any type of programming language, cause I would like some help with algorithms, but I prefer Delphi. I have a the task to detect and count multiple shapes (between 1 and N - mostly circular or a Elipse) of random pictures and calculate their middle and return them as coordinates of a picture. The middle of each shape can have a filling (but it doesn't matter). The shapes are at least 1+ pixel away from each other. None of the shapes will like blend in with another or the corner of a picture.
The background of the picture has always the same background color, which actually doesn't matter, cause the borders/frames of the shapes are always a different color compared to the background. This makes it easy to detect the shapes. I was thinking about going pixel by pixel and collect the coordinates and then draw like an invisible rectangle/square around every shape to calculate the middle. Then I also heard about scanline, but I don't think it would be faster in this case. So my question is, how can I calculate:
How many shapes are in the picture.
How can I calculate (more or less) the exact middle of them.
A few pictures to visualize the task:
This is a picture with random shapes (mostly close circles)
As you can see they are apart from each other just fine.
Then I could easily draw/calculate an imaginary rectangle/square around every shape and calculate the middle of it like that:
After I have the rectangles/squares. I can easily calculate the middle.
How do I start?
PS.: I've drawn some circles in mspaint. I have to add that all shapes are CLOSED, which makes it possible to flood fill EVERY shape in the picture with no problems!
Thank you for your help.
Calculate MSER (Maximally stable extremal regions) for the image. I can't explain that algorithm here. You can refer to the Maximally stable extremal regions article for more information about the algorithm.
That will give you centroid too.
This algorithm is implemented as inbuilt functions in OpenCv tool and Matlab 2012b.
Another method which i can think of and possibly simple than previous method is to apply connected components algorithm and count number of objects.More information of this can be found in book by Gonzalez and Woods on Digital Image Processing.

Detecting location of music note dots in a sheet music image

I want to start a project that uses a very basic form of optical music recognition.
For those who understand sheet music: Unlike other OMR projects, the only information which needs to be extracted is the order and pitch values of each note in a bar. Quarter notes, half notes and whole notes need to be distinguished. Shorter notes can acceptably be interpreted as quarter notes. Dots on notes can be ignored. Dynamics markings are not important
For everyone: Strictly speaking I need to find the locations of each of the following...
... in a sample image like this...
I have no experience in image processing so a basic, conceptual explanation of what technique or set of techniques are used to achieve this would be greatly appreciated.
I would do the following:
Extract the line locations using Hough transform. (You get the angle as well). Crop each group of lines (5 lines), and process individually.
For each group of lines, you know the angle of the lines, so you can get the locations of the vertical small lines that separate the bars. Search again in Hough space, but with specific angle. (The original + 90). Crop each bar and process individually.
For each bar, use template matching on the possible notes (Quarter, Half,etc..)
I did something similar to your work and trust me it is a complete mess.
Howeverr, for the pitch for each note you extract the head from the rest and calculate the baricentre and compare its position to the position of lines calculated with Hough transform as already said (assuming that the lines are already straight: if not i think you can use the Fourier Transform).
For the duration you need a classification algorithm.

Resources