Algorithm to add points at the edge of other points - algorithm

Let's say the initial map has only the red dots. Then I want to add all the green dots. Note that the shape is not always circular.
Any idea how to do that?
I was thinking to consider all as a cluster and then get the edge (or approximation) of the cluster and add new dots.

One possibility that comes to mind would be to conmpute the convex hull polygon of the input, using one of the known algorithms for that. Next, the center of gravity of the convex hull polygon could be used to shift the points of the convex hull outwards, resulting in a dilation of the boundary. If more points for the boundary are needed, one could interpolate between the points of the convex hull polygon.

Related

Intersection of a line and a concave polygon 3D

My problem is to find if a generic (convex or concave) polygon and a rectangular polygon in 3D space has a not-null intersection. Each polygon is defined by the set of the ordinated contour points (if point p1 is after/before point p2 the edge p1-p2 exists).
It is easy to find the intersection line of the two plane of the polygons so the problem is finding the intersections of a line and the finite polygons and if the resulting intersections have a portion in common. I found algorithms for the intersection of a line and a convex polygon but I can't find anything for the general case of concave polygon.
Any suggestion?
Thank you
find the intersection point of the plane-intersection line with every edge of both figures. From there its s straightforward problem of looking at the ordering of the points on the line to check for any overlap.
Of course the special case where they are coplanar is a whole other problem..
There are usually no fast solutions for concave polygon intersection / containment/ etc queries.
The general solution is always to triangulate the polygon into a series of convex triangles, then run your intersection test with those triangles.
If you can rely on the polygon to be planar, you can first intersect the line with the plane and then transform the intersection point into the coordinate system of the plane.
Assuming you have also transformed all the vertices of the polygon, the problem is now to decide whether the 2D intersection point is within a 2D polygon.

check whether a point is visible from a face of a 2d convex hull

I am trying to implement the Bowyer-Watson algorithm for generating a Delaunay Triangulation of a set of points in a plane. The algorithm assumes a presence of a bounding super-triangle, but some alternatives like maintaining the convex hull of the set of points have also been mentioned.
Thus, when we decide to produce a delaunay triangulation of points by assuming a convex hull in an incremental algorithm, if a point lies outside the convex hull, we should draw vertices from the point to all the vertices on the convex hull which comprise the faces of the hull from which the point is visible.
I was wondering how could I approach this problem? Should I initially generate a convex hull of all the points or like in the incremental approach where points are added one at a time, should i maintain a convex hull in the form of a DCEL?
EDIT: In the image above, if I have the point P which is outside the convex hull of a set of points in a plane, I need to calculate the edges of the hull from which the point is visible. [The green edge of the hull]
I hope the image helps in clarifying the question.
Thanks in advance
The edges that see P are those that form a clockwise triangle with P when the hull is traversed counterclockwise (compute the signed area).

Rectilinearize a non-intersecting polygon

I have some non-intersecting polygon, and I need to "square" it up so that all angles are 90 degree angles.
Is there a good algorithm to do this?
EDIT
Allowing self-intersections in the resultant polygon, I'm looking for the "best" method of tesselating rectangular shaped tiles in the original polygon. The rectangles can span the original edges of the polygon, and the goal is to fit the most rectangles squarely into the polygon.
You can replace each side of the polygon with a "staircase" which resembles the original side, like so:
the more "steps" you add to each staircase, the closer it resembles the original shape.
It is not guaranteed that you can avoid self-intersections if you allow just one new segment per original segment.
You can use a quadtree to subdivide the line segments until each line segment is alone in its quadtree cell (alternatively you can subdivide further until some approximation ratio is reached). Then replace each line-segment by two line segments of its bounding box.
hth

Intersecting a minkowski difference from the origin in a direction, how do i find the face im intersecting?

Basically i have a set of vertices on the hull of a minkowski difference of two polyhedra. I want to find the distance from the origin to the hull in some arbitrary predetermined direction. Heres a quick 2D sketch:
So the issue is finding what triangular face/plane the ray is going to intersect. Once i have that plane i simply do a line/plane intersection test. My issue is finding the correct face/plane. Any ideas? Is there some set of dot product/cross product/triple product tests i can do to determine it? Or is it more complicated then that?
If your wondering what this is for im using a GJK algorithm to determine whether two objects are intersecting (which i've got working). If there is a collision i would like to find the penetration depth in a particular direction (which will be the direction of motion of the object).
Project the polyhedron in the direction of the ray, and your problem reduces to 2D, and finding which triangle encloses the origin. To test a single triangle, consider whether a given directed line segment (AB) is going clockwise or counterclockwise with respect to the origin. This is easy to determine with a simple cross-product test: it's counterclockwise iff A x (B-A) > 0.
If all three sides of a triangle have the same sense (clockwise or counterclockwise) then the triangle encloses the origin and that's the face you want.
EDIT:
Since your polyhedron is a hull it is convex, And since it is convex you can search the surface in an efficient way. You can traverse the edges in a very simple "walk uphill/downhill" way to find the two vertices farthest along the the ray in either direction. Then after you project the poyhedron you can start from these two points and do a similar climb toward the origin. This will be O(sqrt(n)).

Finding a stable placement of an irregular (non-convex) shape

Given an image of a 2-dimensional irregular (non-convex) shape, how would I able to compute all the ways in which it could lie stable on a flat surface? For example, if the shape is a perfect square rectangle, then it will surely have 4 ways in which it is stable. A circle on the other hand either has no stable orientation or every point is a stable orientation.
EDIT: There's this nice little game called Splitter (Beware, addictive game ahead) that seems close to what I want. Noticed that you cut a piece of the wood out it would fall to the ground and lay in a stable manner.
EDIT: In the end, the approach I took is to compute center of mass (of the shape) and compute the convex hull (using OpenCV), and then loop through every pair of vertices. If the center of mass falls on top of the line formed by the 2 vertices, it is deemed stable, else, no.
First find its center of mass (CM). A stable position is one in which the CM will be higher if you make a slight rotation. Now look at the hull, the smallest convex region that encloses the shape:
(source: walkytalky.net)
If the hull is a polygon, then a stable position is one in which the shape is resting on one of the sides, and the CM is directly over that side (not necessarily over the midpoint of the side, just somewhere over it.
If the hull has curves (that is, if the shape has curves which touch the hull), they must be give special treatment. The shape will be stable when resting on a curved edge iff the CM is directly above the lowest point of the curve, and the radius of the curve at that point is greater than the height of the CM.
Examples:
A rectangle. The hull is simply the rectangle, and the CM is at the center. The shape is stable on each of the four sides.
A rectangle with the sides hollowed, but the corners still intact. The hull is still the original rectangle, and the CM is close to where it used to be. All four sides of the hull are still stable (that is, you can still rest the shape on any two corners).
A circle. The CM is in the center, the hull is the circle. There are no stable positions, since the radius of the curve is always equal to the height of the CM. Give it a slight touch, and it will roll.
An ellipse. The CM is at the center, the hull is the shape. Now there are two stable positions.
A semicircle. The CM is somewhere on the axis of symmetry, the hull is the shape. Two stable positions.
A narrow semicircular crescent. The hull is a semicircle, the CM is outside the shape (but inside the hull). Two stable positions.
(source: walkytalky.net)
(The ellipse position marked with an X is unstable, because the curvature is smaller than the distance to the centre of mass.)
note: this answer assumes your shape is a proper polygon.
For our purposes, we'll define an equilibrium position as one where the Center of Mass is directly above a point that is between the leftmost and rightmost ground-contact points of the object (assuming the ground is a flat surface perpendicular to the force of gravity). This will work in all cases, for all shapes.
Note that, this is actually the physical definition of rotational equilibrium, as a consequence of Newtonian Rotational Kinematics.
For a proper polygon, if we eliminate cases where they stand on a sole vertex, this definition is equivalent to a stable position.
So, if you have a straight downward gravity, first find the left-most and right-most parts of it that are touching the ground.
Then, calculate your Center of Mass. For a polygon with known vertices and uniform density, this problem is reduced to finding the Centroid (relevant section).
Afterwards, drop a line from your CoM; if the intersection of the CoM and the ground is between those two x values, it's at equilibrium.
If your leftmost point and rightmost point match (ie, in a round object), this will still hold; just remember to be careful with your floating point comparisms.
Note that this can also be used to measure "how stable" an object is -- this measure is the maximum y-distance the Center of Mass can move before it is no longer within the range of the two contact points.
EDIT: nifty diagram made hastily
So, how can you use this to find all the ways it can sit on a table? See:
EDIT
The programmable approach
Instead of the computationally expensive task of rotating the shape, try this instead.
Your shape's representation in your program should probably have a list of all vertices.
Find the vertices of your shape's convex hull (basically, your shape, but with all concave vertices -- vertices that are "pushed in" -- eliminated).
Then Iterate through each of pair of adjacent vertices on your convex hull (ie, if I had vertices A, B, C, D, I'd iterate through AB, BC, CD, DA)
Do this test:
Draw a line A through the two vertices being tested
Draw a line perpendicular to A, going through CoM C.
Find the intersection of the two lines (simple algebra)
If the intersection's y value is in between the y value of the two vertices, it stable. If the y values are all equal, compare the x values.
That should do the trick.
Here is an example of the test being running on one pair of vertices:
If your shape is not represented by its vertices in your data structure, then you should try to convert them. If it's something like a circle or an ellipse, you may use heuristics to guess the answer (a circle has infinite equilibrium positions; an ellipse 4, albeit only two "stable" points). If it's a curved wobbly irregular shape, you're going to have to supply your data structure for me be able to help in a program-related way, instead of just providing case-by-case heuristics.
I'm sure this is not the most efficient algorithm, but it's an idea.
If you can order the verticles of the polygon (assuming it has a finite number of vertices), then just iterate over adjacent pairs of vertices and record the angle it rests at through some form of simulation. There will be duplicate orientations for it to sit on in the case of weird shapes, like stars, but you can accomodate for that by keeping track of the resting rotation.

Resources