I'm trying to write a small drawing app where I want to be able to draw shapes by hand and the app will identify the kind of shape and redraw it using vector graphics.
Supposing that I have a list of 2D points that represent the following image:
What algorithms should I use in order to:
Determine that the shape is a square and not another shape or curve/arc;
Determine the edges of the square
Related
I am trying to generate random shapes of equal areas. I am following another post where random shapes are created https://stackoverflow.com/a/50751932/11078529
Is it possible to put a constraint like equal surface area while generating shaped using Bezier curve.
I want to know the basic idea of creating 2d views of a 3d geometry in cads like autocad, solidworks, and etc..
Here, I listed some basic ideas that I had reached now.
Which method are they used ? or any method I didn't listed ?
idea A:
first, to render every single face to a plane space.
then detect the boundaries of faces.
do something magic that can recognize the 2d curves from the boundary pixels .
do something magic again to recognize which segments of curves should be hiddened.
construct a final view from lines and curves generated from above steps.
idea B:
they create projection rules for every type of surface with boundary wires, like plane, cylinder, sphere, spline. And thoes rules can be used in all projection angles.
then, implement projection rules for every face, and finally they got a view of many curves.
to iterate all curves generated from step 2, and check the visibility of the curve.
construct a final view.
idea C:
first, tessellate every faces to many triangles.
then, found boundaries from triangles for every faces.
then, we got many polylines from step 2.
to iterate all polylines generated for every faces, and check the visibility of the polylines.
construct a final view.
I found a solution, it follows this way:
tessellate every face and edge to triangles and segments.
project all those triangles and segments to a plane.
then choose a suitable resolution to construct those projected triangles and segments to pixels with a height parameter.
found contours for every face and edge from those pixels.
set visible value for every pixel on that contour depends on the height parameter of a total pixel's view.
reconstruct line, circle, and polylines from pixels.
I tested this method for some models, and works well. below is one of them:
I am developing a web app and I need to find a way to draw an outline rectangular polygon connecting the given points to form a perimeter on a coordinate system.
I found this ordering shuffled points that can be joined to form a polygon (in python)
to be quite relevant to my problem, but it has the problem that, if any points surpasses the center of the polygon the algorithm does not work...
To make it more clear what I want I am attaching two pictures to show what I want to achieve with given points:
Correct way to join points
Wrong way to connect points
Is there an algorithm that given point coordinates creates the rectangular perimeter as I want it? Thanks
I try to create a scene for physical simulation. The scene consists of rectangular floes floating in a rectangular pond. Something like this:
So I need to fill a rectangular area with non-intersecting rotated rectangles with widths and heights in a specified range. I don't need to find an optimal coverage of the area. The goal is just to generate floes of different size without intersections.
And I'd like to get a solution without any dynamics, only using collision detection algorithms.
You could consider simulating a collection of boxes falling into a square bucket and saving the positions of all the boxes once they come to rest.
box2d is an open source 2D physics library that can do this for you - you might recognise it as the physics engine behind Angry Birds and umpteen-million Flash games.
There is what I would do:
Suppose the length of the rectangles are between [MaxSize MinSize]
r <- MaxSize
do{
Trying adding non-intersecting circles to the area with radius r and random center (x,y). We use circle instead of rectangle because intersection detecting for circles are easier than rectangles. e.g. if distance(x,y,x',y')<r+r' then we are good.
If adding circle failed{
r--;
if r< MinSize break;
}
}
Now you will have a plane full of on intersecting squares. There will be gaps because we were using circles as intersection detection. If this is not good enough for you, grow the squares to rectangles. You can do this by checking all points against a certain border and decide how much you can grow it.
To model solid (ie non-intersecting) objects, you could use a physics engine. As it happens I just the other day read Farseer tutorial for the absolute beginners, which includes a video depicting almost exactly your requirement. Farseer is a .NET version of box2d, which you may have heard of.
I have a set of points that outlines my polygon. The polygon can have many different shapes including convex shapes (imagine the shape of a crescent moon). I thought I could fill the inside of these shapes by using a triangle fan that started at the first point on the perimeter, but this fails badly on certain shapes.
How do people get this done? I wish there was a glPaintBucket function.
I believe you need to use the (intrinsically filled) triangle primitive after breaking up your polygon into triangles (start here to learn about polygon triangulation).