so I have created a circle with draw method :
glLineWidth(16);
glColor4ub(0, 255, 0, 255);
drawCircle( ccp(s.width/2, s.height/2), 100, 0, 10, NO);
I would like to know if it is possible to transform this shape to a rectangle shape with animation . Thank you . sorry for my english I'm french :/
For simplicity, I'd use 4 cubic bezier curves - one curve per quadrant of the circle. (This isn't a perfect circle but neither is a 100 segment circle!) Then, using the schedule: functionality provided by cocos2d, I would gradually move each curve's control points over time until they line-up vertically or horizontally with the curve's origin and destination. This turns the curves into 4 straight lines: a rectangle!
Well, a square to be exact. You'll also have to move the origins and destinations of all 4 curves to form a rectangle that is not a square, but you get the idea I hope?
See these links for additional info:
Bezier Circle math - http://www.cgafaq.info/wiki/Bezier_Circle
cocos2d - ccDrawCubicBezier - http://www.cocos2d-iphone.org/api-ref/2.0.0/_c_c_drawing_primitives_8h.html#a5a391711c0aa611a06167bdd7637571f
cocos2d - schedule: example code - http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_2._your_first_game#making_things_move
EDIT: added image
d = d value calculated from equation at: http://www.cgafaq.info/wiki/Bezier_Circle
start, control 1, control 2, and end are the 4 points needed to make a cubic bezier curve in cocos2d.
You will have to write the code for this.
You could, for example, create a number of control points that are around the circle. Each of these control points could consist of 3 points. Two points that represent two points on the circle and one point that controls the curve of the line drawn between the two points. Now you animate the motion between the control points on the curve such that they move to become the control points on a rectangle and at the same time animate the motion of the third control point so the edge changes from a curve to a straight line.
Related
I'm using canny edge detection to detect the edges of a rope and eliminate the background, then using morphological filters I'm filling these edges then thinning them to be in pixel size. The plot indicates the xy coordinates of the rope. What I need to do is to get the intersection of the scattered data (blue *) with the red circle (get the coordinates of Points (1,2,3,4).
Then I need to get the whole points coordinates from the point of intersection (point1,2,3,4) to the center,grouped as A,B,C,D.
The center of the circle, the origin of the axes, and the radius are all known.
I've tried some Matlab functions to get the four intersections points like
InterX,intersections
and also I tried to manually find the intersections
idx=find(y1-y2<eps);
but no method gives me the 4 intersection points.
Thank you in Advance
You'll need a thick circle. I presume (from your previous question) that the rope points are at contiguous integer coordinates. Using a thick circle (donut) with a width of 1 ensures you'll find at least one point in each rope end. Connected component analysis will then tell you which of these points belong to the same rope end.
I am trying to find the shape of a curve shape rod in its plane, based on two perpendicular views of the rod. I have prepared an image to make my question clearer.
I have the projected images of the rod on the planes 1 and 2, and I'd like to produce the image of the rod in plane 3. What I have done is that I found the center line of the rod on views 1 and 2 using Matlab image processing toolbox, then I fitted a curve on those lines. Then I produced 3D data based on those fitted curves, and finally fitted another curve or ellipse to the final 3D curve.
It works, but I am wondering if there is any more appropriate solution, for example by rotating the views 1 and 2.
The angle of the view 3 with respect to view 1 (and view 2) is variable, but views 1 and 2 are perpendicular to each other.
We can find the angle of the plane 3 by finding the end of the rod in the views 1 and 2, as it would be atan(x_end_in_view_1/x_end_in_view_two). Is it possible to produce the image from the view point of a camera angled to a known degree from another camera, based on the image from the second camera?
Any help is highly appreciated.
Yes, it is possible to produce the image from the view point of a camera angled to a known degree from another camera. Given the angle, you can compute the affine transformation between the two planes and apply the transformation to the original image to get the projection of the image in another plane.
There are 6 parameters for an affine transformation, and since you know the angle between the two planes, for 4 points (0, 0), (0, 1), (1, 0) and (1, 1), you would know the (x, y) co-ordinates of these points after you tilt your plane (say about the y axis) (forget about the z-coordinate). Now, you will have 8 equations and 6 unknowns, hence you can compute the affine transformation and apply the transformation on the complete image to get the projection.
In the following screen shot:
when you drag the tail of the word balloon (the thing that connects from the balloon to the persons mouth), the shape curves (as illustrated by the difference between the two balloon tails in the picture). I'm wondering, how is this done? I'm assuming you need to start with a CGPath and do something to it, does anyone happen to know what this is?
Update: So if I wanted to curve the following shape:
Would I use the following code:
CGPathAddCurveToPoint(mutablePath, NULL, x1, y1, x2, y2 + constant, x5, y5);
CGPathAddCurveToPoint(mutablePath, NULL, x3, y3, x4, y4 + constant, x5, y5);
Where the constant readjusts the y position of point 2 and point 4 to make the curve?
You need to exploit the fact that, mathematically, a straight-line segment is just a kind of curve segment.
(It's easier than it sounds, trust me.)
Bézier path segments have something called “order” that essentially determines how many points there are in the segment, not counting the point you're coming from.
A straight-line segment is a first-order curve, meaning that it only has the destination point. These “curves” are always straight lines because there are no control points to curve toward.
Quadratic curves are second-order curves (one control point plus the destination).
Cubic curves are third-order curves (two control points).
(The math doesn't put any limit on this, but Quartz stops here. No fourth-order curves for you without rolling your own rasterizer.)
This matters because any lower-order curve—including a straight line—can be expressed as a higher-order curve.
So, the secret?
For even a straight tail, use a curve.
(Namely, a cubic curve, since you want the curve going in two different directions: One, more or less into the tail, and the other, more or less along the edge of the balloon.)
From each of the two points at the base of the tail, you want one of the control points to be about halfway to the destination. This much is unconditional.
The direction of each of the control points gives you three options:
The straight-out tail
Notice the two control points along the blue line at the vertical center of the image.
Notice the direction of these two control points, relative to the base point it's connected to. They are angled inward, toward the tip—indeed, exactly on the straight line to the tip.
The oblique tail
Here, the tip point is no longer horizontally between the two base points. The control points have moved, but only to follow: each one is still halfway along the straight line between the corresponding base point and the tip.
The curved tail
For a curved tail, you move the tip, but you keep the control points at the same position as for a straight tail. Thus, the tail starts out straight out (following the control points), but as it gets farther from the base points, their influence wanes, and the tail begins curving toward the tip.
This is a lot easier to describe visually than to put into code, so you may want to consider using something like PaintCode or Opacity to draw each kind of tail using a pen tool and then see what the code they generate for it looks like.
You can use the CGContextAddCurveToPoint() functions:
CGContextMoveToPoint(ctx, x, y);
CGContextAddCurveToPoint(ctx, outTangentX, outTangentY, inTangentX, inTangentY, newX, newY);
... // more points or whatever you need here
CGContextFillPath(ctx); // Fill with white
CGContextStrokePath(ctx); // stroke the edges with black
The in/out tangents can be hardcoded to be something that looks good based on the point on the mouth of the picture and the point where it meets the balloon bubble. You might try something like making their angles half-way between perpendicular and the slope of the straight line between the 2 points or something like that as a starting place.
I'd like to create a fixed size circle that will have a varying number (between 6 - 12) of rectangle sprites positioned on it. I've read about a cocos2d function called drawCircle which is great for displaying a circle. I'd like to display a circle, but I'd also like to include the rectangle sprites on top of it, spaced evenly depending on the number of sprites.
Is there a function that would layout the rectangle sprites in a circle?
I see a little bit of trigonometry in your future! Perhaps draw the circle using a drawing function, and then compute points for the center of each box?
You'll need to know the radius of your circle, obviously, but from there it should be pretty simple. It looks like you want to place them at 45 degree angles. So the first box would be placed at point (radius, 0), the second at (radius*cos(45), radius*sin(45)), third at (0, radius), etc.
The above math is assuming standard counter-clockwise rotation from 0-360 degrees. You can also use radians - you would then compute all these points with theta = 0, pi/4, pi/2, 3pi/4, pi, 5pi/4, 3pi/2, and 7pi/4
Basically is the circle center is x0, y0, your calculated points will be (x0 + radius*cos(theta), y0 + radius*sin(theta))
Should be fairly simple math at play there :)
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