How do I draw a path along some defined points in a way so that the path is nicely curved and not necessary exactly touching the defined points, except the end points where the line must be ending at the exact points? I have tried with quadTo, but that gives me jagged connections between the quadTo end/start in some situations.
To illustrate what I want I have attached this example image:
Thank you
Søren
Related
Could someone explain me how convex path is calculated? I need to draw some cubic and additionally some lines but then path is shown as non convex. However when I leave only lines or just cubic it is then convex. The problem is that I need some non regular shaped background and need Convex path for shadow outline but can't get how I could connect drawing cubic with some lines to make convex path if it is even possible
A path is convex if it has a single contour, and only ever curves in a single direction.
Convex means it keeps bending / rotating in one direction, and one direction only. You really have to make sure that all your angles and curves add up. If your curve connects to a line it has to have the same angle or be "more convex", I hope the following 2 images will clear this up.
The picture below is not convex. That's also likely your problem. The line connects to a curve, but the curve has a different angle than the line and it will change the direction where it connects. See where the line goes down but instead of continuing the downwards-motion it suddenly goes up again. Instead of keeping one direction it will change for a moment where line and curve meet.
The above Image is exaggerated for clarity, but even small errors in the connection between the line and curve will trigger an error.
The next line connects to a curve with a steeper angle. This is convex and won't be a problem. See how the whole contour keeps a single motion in one direction, depending in which direction you follow it it keeps turning left/right.
I answered because I was facing a similar issue recently and I feel your pain. I recommend pen and paper to double and triple check the math and to use a small epsilon value to account for rounding errors etc... You really have to nail the math, because if your line and curve connection is just off by very little it will throw that exception.
Sorry for my bad paint skills
Okay, so I have two very simple separate Path objects, one containing a straight line I created with lineTo and one containing a curve that I generated with the quadTo function. I need to get the POINT (x, y) where these two objects insect, which they only do once as well as the DISTANCE from one side of the arc of the point where they intersect.
There are lots of posts about figuring out IF they intersect, but I can't find any information on how to figure out WHERE they intersect.
EDIT! I still can't figure this out, I've been trying to fake it by measuring the distance along the yellow line that the black lines were drawn apart from each other and then making a whole new curve. It's sloppy and not working well. See the image!
If I can get to the distance from the end where the black curve intersects the yellow line, I can get a segment of the curve, and the two points on it's end, and it will work great!
Any ideas, anyone? :)
Thanks!
I am drawing a path when a user drags his finger across screen. If, however, he does this too fast, I get too few points in path. Is there some way, I can increase the number of points in path after the user has drawn it?
I need this because I am comparing each point of path1 to all points on path2 to see when these two paths are intersecting.
If the user has already completed drawing a path, the best you can do is work with the points you have and guess at what goes between them. Two popular methods of guessing are to insert line segments between points, which gives a very jagged look, or you can use spline interpolation, which gives a very smooth look, but involves a more complicated calculation.
More info on spline interpolation: http://en.wikipedia.org/wiki/Spline_interpolation
Whether you use line segments or splines, you'll need to mathematically find the intersection by using the equations for the path1 segment/spline and the path2 segment/spline. You'll have two equations, two variables and so you should be able to solve the system to find the values for x and y that satisfy both equations, making that point the intersection.
http://en.wikipedia.org/wiki/Line-line_intersection
I am new to AndEngine and very happy that it's very easy and exciting thing to do. Unfortunately I am unable to draw a curved line in AndEngine.
Actually my scenario is that I have an animated sprite say Object. I want to move this object on a Line with the points given onToucing and dragging it. Now the problem is that I can't find any method to draw a line on points in a way that it does not produce corners. I want a smooth line with no corners.
Suppose I touch the object and drag it on the screen with the points of a square type region. But I don't want the corners in it. I want curves. Previously I am doing this by using quadTo(..) function of android to do this. All I want is a complete alternative to quadto function in AndEngine but with same functionality.
You have to stitch together the curved line from many many small straight lines.
Moving an object along a line is a very different task though. You'd want to have a look at CubicBezierMoveModifier and QuadraticBezierMoveModifier for those.
Maybe you can actually use the code in those modifiers to create your 'smooth' line.
I have written my own poly-line class that essentially keeps a list of points that can be modified using a Matrix. The poly lines can be added to other poly lines and joined at common endpoints. The poly line will represent a polygon when the end point equals the starting point.
I then have a method to turn my polygon into a Path object by iterating the list of points with a series of lineTo() calls. This path is then applied to a canvas as a clip path in my View's onDraw method.
It works perfect for complex polygons and I can draw that path to verify it's accuracy.
So far so good, except that I'm noticing issues when I have a compound polygon with an irregular hole in the middle. I should probably stop calling it a polygon at this point since it is a polygon inside another polygon.
For example consider the diagram below where the outer box and "castle" looking shape in the middle are both parts of the same Path object that is used as a clip-path. The # represent painted area.
+---------+
|#########|
|#+-+#+-+#|
|#| |#| |#|
|#| +-+ |#|
|#| |#|
|#+-----+#|
|#########|
+---------+
I expect that everything outside of the outer box and inside the inner "castle" shape to be clipped. The issue I'm seeing is that the inside shape isn't being clipped, properly. Seems to be an issue with the ray-tracing algorithm.
Any ideas would be helpful.
EDIT: Also, I tried testing every Region.Op mode, and none of them solved the problem. I suspect I'll need to put measures in place to detect if there is a "hole" and do something creative.
After spending a couple of day's playing with this I've half-solved my problem.
I needed to set the Path.FillType with:
path.setFillType(Path.FillType.EVEN_ODD)
But then I had an instance where the opposite happened and only the center path was painted. A little more investigation and I was able to fix that with adding:
canvas.clipPath(path, Region.Op.DIFFERENCE);
But then polygons with a single path on the outside have their clip inverted. While I'm satisified that I've found the right nerd-knobs to get the right clipping behavior, I haven't found a way to determine which clipping methods are needed.
I'd be happy if someone has any ideas to share. I suspect it has something to do with the order in which lines are added to the path, such as if the inner is defined beore the outer, etc.