EPS has the arc command
xcenter ycenter radius startangle stopangle arc
which will draw a circular arc at the desired around the desired location. How can I draw an ellipse?
With curves :-)
You need to look at the curveto operator, then define your ellipse as a series of Bezier curves.
See also the answer to this question
Related
Can konva draw an ellipse arc?
I want to draw an ellipse arc(spanAngle = 180)with two different radii such as 40 and 70.
Is there an API that I can use?
https://konvajs.org/docs/shapes/Arc.html in this demo i can only draw circle arc ,now i want to draw an ellipse arc(different radius are 40 and 70)
Me and my team are working on an app for a client. We are trying to understand how to achieve this kind of animations (refer only to the circle stroke) :
We tried using a CADisplayLink to set up and change the circle, but it generated non-fluid results.
We couldn't find a way to create a circle from "components" of UIBezierPath and change each of the anchors.
Any suggestions on how to achieve this kind of effect, or how to construct a circle from seperated points, would be highly appricated
Best Regards,
Roi and the team
I suggest using Catmull-Rom splines. Those allow you to create smooth curves using only points that are on the curve, whereas Bezier curves require that you define control points that are not on the curve.
Once you have beginning and ending CGPaths its pretty easy to create a CAAnimation of the path from it's starting to it's ending state (although animating change to a CGPath only works correctly if the starting and ending paths in the animation have the same number and type of points.)
You could probably also use Bezier curves, but you would need to generate the control points for the circle and it's distorted shape.
Check out this sample app that uses Catmull-Rom splines to create a distorted circle shape:
http://wareto.com/animating-shapes-using-cashapelayer-and-cabasicanimation
(Written in Objective-C, but the technique is the same in Swift.)
A Catmull-Rom spline with 8 control points evenly spaced around a circle where the distance from the center of each control points is varied by ± r/12 seems about right:
I am drawing ellipse using following UIBezierPath method:
UIBezierPath *bpath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x, y, width, height)];
This gives me something like below:
But I want to draw ellipse at an angle like below:
I know one solution is to rotate the UIView. But I cannot do this because same view contain other bezier paths. So I want to know if there is any way to draw this ellipse at an angle?
Often the easiest way is to put this on a CAShapeLayer and then rotate the layer. The math for that tends to be very simple (particularly if you want to change the transform later). But you can also just rotate the path directly before drawing it by creating a rotation transform (CGAffineTransformMakeRotation) and using -applyTransform: to modify the path.
I want to find that minimum circle radius that cover circular arc. here is a api link that i need but i think it is not open source:http://reference.mapinfo.com/common/docs/mapxtend-dev-web-none-eng/miaware/doc/apidoc/com/mapinfo/miAware/geom/CircArc.html
A function should be like that and it will return Circle.
public Circle CircArc(double x, double y, double inRadius, double outRadius, double startAngle, double stopAngle)
after i will be able to get center of circle coordinates and radius like that:
circle.getXCoord();
circle.getYCoord();
circle.getRadius();
Is there any api?If not how can i implement CircArc function?
Compute the locations of the two endpoints of the outer circle. There are two cases:
if the arc aperture is smaller than a half turn: the diameter of the requested circle is the line segment between these endpoints,
otherwise: the circle is just the circle of support of the arc.
Anyway, there remains a difficult configuration with arcs of a small aperture such that the inner arc might pass the circle defined above.
How to eliminate the boundary between triangles?
I'm implementing export-to-pdf in my triangle drawing app. The image above shows what the pdf output looks like. There are white boundaries everywhere, less than 1 pixel wide.
The triangles can have any color.
I draw each triangle, like this:
CGContextBeginPath(context);
CGContextMoveToPoint(context, x0, y0);
CGContextAddLineToPoint(context, x1, y1);
CGContextAddLineToPoint(context, x2, y2);
CGContextClosePath(context);
CGContextFillPath(context);
It's important that black and white triangles have the same sizes.
Approaches
Approach 1 - Stroke
Draw a 1 pixel thick stroke around all triangles.
Approach 2 - Extrude
Extrude all triangles by 2 pixels so the triangles overlaps.
Approach 3 - Combine
Combine touching triangles into a single polygon.
Approach 4 - PDF overlap settings
Perhaps PDF has settings for eliminating boundaries. Dunno.
Approach 5 - Post processing
Create a filter that detects boundary pixels and eliminates them. This will not work for me, it needs to be saved to a PDF. Shader code is not supported in PDF on iOS, AFAIK.
Approach X - A smarter way
Is there a better way of snapping triangles together?
Are your coordinates (x0, y0, x1, y1, etc.) at integer point values? It's common for people to make that mistake because they're used to setting views' frames to be on whole point boundaries. CoreGraphics draws with one point lines drawn centered on the coordinates you provide. I suspect that you can eliminate your artifacts by adjusting your coordinates by 0.5 points in all cases:
CGContextBeginPath(context);
CGContextMoveToPoint(context, x0 + 0.5, y0 + 0.5);
CGContextAddLineToPoint(context, x1 + 0.5, y1 + 0.5);
CGContextAddLineToPoint(context, x2 + 0.5, y2 + 0.5);
CGContextClosePath(context);
CGContextFillPath(context);
Edit: Actually I don't think this is going to work. Here's another suggestion:
I'm leaving my previous comments because I think what I said about the CoreGraphics coordinates is true, but I tried some experiments with the setup you described and shifting everything over didn't eliminate those border artifacts. However adding this line did:
CGContextSetAllowsAntialiasing(context, false);
(I don't know why CGContextSetAllowsAntialiasing is declared to take a stdbool style bool, but it is, that's why I used false instead of NO here, not that it makes a difference.)
Cheap/Easy solution is to draw each triangle twice. This will reduce anti-aliasing but boost the coverage along the edges. Rendering as a single path should work too if it's all the same color.
Approach 3 - Combine
I'm using GPC – General Polygon Clipper library and it almost works as desired.
I run a UNION operation one triangle at a time. Until all triangles have been UNION'ed into the result.
Below is output from GPC. No white edges can be seen.
I also tried using Angus Johnson's Clipper library, but was unable to built polygons by UNIONing one triangle at a time. It only removed a few of the white edges between triangles. Although Clipper seems more powerful than GPC.
Below is output from Clipper, it shows white edges.