Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a set of 2D points and I want to find the potential largest empty circle. By that, I don't mean to code the Largest Empty Circle algorithm.
Here's an image trying to explain my words.
As you can see, there are points inside that circle, so what I want is an algorithm that given that set of 2D points, could compute that circle.
That set of points represents a wall of a sewer which contains a hole. The problem is that this hole may be corked, may contain some dirt at one or more sides of the circle. So, when you laser detect that part, you don't obtain a perfect circle, but kind of a semicircle. What I want to find is the original hole, the clean hole, when there is no dirt. When I say potential, I mean the original hole. In the image, the green circle is the original hole and the points inside that circle are some kind of dirt. The final purpose of this is to decide whether the hole is clean or dirty (Detecting how many points are inside that green circle and decide how dirty it is)
Another example of how it is supposed to be in real life:
Here you can see that the hole has dirt in the bottom part (could be any side of the hole), so when you laser detect it, you don't obtain the circle, but a bunch of points with the upper part of the circle as empty. What I want is from that set of points where you can only see the upper part of the circle empty, reconstruct the original hole, as it was when clean.
Plus, I attach two images of the point cloud, from two different perspectives, so you can know what I am working with.
I would find the bounding box of hole and then inspect the sides. find the one that is not linear but curved instead and set that as circle border. Then fit circle to that side only. For more info see:
fitting ellipses
Finding holes in 2d point sets
If you can scale the coordinates in order to draw the point into an image, here is a solution:
Draw the points into an image
Compute the distance map using all the points as a source point.
Then, each pixel will contain the distance to the closets point. So the pixel with the highest value will be the center of the largest circle, and the pixel value will be the circle radius.
Find the closest points to the circle center.
Find the circle passing by all theses points (Hough?). The solution might not be unique.
Related
How can I achieve the reverse of a k-nearest search, so that I can find geometries thar are farthest away from a given center geometry?
Background: This is about map tile caching. I want to remove irrelevant tiles which are far away from the current view.
The furthest rectangles are always at the limits. So you need to get the minimal enclosing circle, which is defined by three extremal points. The most distant from any given point within the minimal enclosing circle is then the nearest to the most distant point on the circle, which is found by taking a ray from the point in question through the origin until it hits the circumference.
So if you need many most distant neighbours, you set up a structure which tags each arc of the minimal enclosing circle with its nearest neighbour, then you can find them quickly.
However it's unlikely you actually want this. You have a rectangle of interest, and now simply exclude everything outside of it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to find a way of drawing the inside of a closed 2D curve. This curve is actually created using a bicubic Bezier curve, but that's not important I believe.
At the moment there should be no "holes" within the drawn shape. So it will just be totally filled in. It seems like constrained Delaunay triangulation would be the way to go? But there seems to be different ways of doing this. I am looking for a quick and simple solution (but will implement what's needed to make it working).
Programs such as Illustrator have that sort of feature (or SVG -- with the option fill).
I am looking for:
techniques to do that
point me to a paper/document where the algorithm is explained
is the source code of a SVG renderer available somewhere?
EDIT:
The application uses OpenGL. I draw the curves myself. Just need to find a way of filling them in.
the shape can either be concave or convex
Polygons can be filled using the Scanline method. The principle is easy: move an horizontal line and keep a list of the edges it meets. It is called the active list. Then join the intersections from left to right, in pairs. When the edges are sorted by increasing ordinate, the update of the active list from one scanline to the next can be done efficiently.
This works with concave/convex polygons and polygons with holes, and even crossed ones.
To fill a Bezier path, you can flatten it, i.e. turn it to a polygon of many sides.
A direct approach is also possible, based on the scanline idea: first decompose the Bezier curves in monotone sections, i.e. portions that meet on horizontal line only once. This can be done analytically for cubic Beziers by detecting the curve maxima and minima (the equation is quadratic).
Now you can treat the curvilinear polygon exactly as a polygon, knowing that you have one intersection per side. There is a slightly delicate point, computing the intersection. But this is eased by the fact that you know a good approximation of the Bezier arc (the line segment between the same endpoints), and you can update the intersection incrementally, from one scanline to the next.
On the picture, the original endpoints appear in blue. Splitting endoints have been added to obtain monotone sections (the other control points are omitted). The dotted lines shows the polygon that approximates the shape and has the same topology (same active list, same number of intersections with the scanlines).
If you must use polygon filling, there is no other option than flattening the curve to get straight sides.
Then use a polygon filling primitive.
If all you have is a triangle filling primitive, you can
triangulate the polygon by ear clipping, or decomposition in monotone polygons, or
use a simple sweepline method: if you draw an horizontal through every vertex, you will slice the polygon in triangles and trapezoids. A trapezoid can be cut in two triangles. For efficiency, use the active list method.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I've been messing around with simple game development for a while and just found an interesting game idea on squidi.net/three/entry.php?id=85 . I'm using SFML 2.1 with C++ and I have a tilemap in a VertexArray that displays the level. Here is what I have so far and you can see my simple tileset: LINK. I am pretty lost in terms of how to handle collisions between the submarine (which is not on a grid based movement system) and the walls. The problem is that say the sub approaches tile 2 (check the tileset image) from the bottom, if I check a collision between the sub and the whole tile the sub will stop before it even gets to the actual wall in the image. Here is an image to help explain this: LINK.
Sorry for the previous confusion and I hope this isn't as bad as before.
Any help is greatly appreciated.
Thanks,
Karel
Edit: Rewrote the question to try to make it clearer.
I will warn you that simple grid based collision breaks down horribly if the object in question moves faster than the resolution of your collsiion tiles. Pretend that your collision boxes are 8x8 pixels in size. Now, what happens when the submarine moves say 16 pixles per tic? You can see that it can jump through single thickness collision walls if you are not very careful on how you check for collision - checking every tile the submarine hits while moving instead of updating the position by the velocity directly. It is even worse than this though - image that you are moving only 2 pixles per second and just clip the edge of a tile, but end on the other side - again the tile based collision, without code that traces every block you touch while moving, will fail.
A more generic way is to use line or vector based collision. Basically, instead of a tile map, use a list of vectors that represent wall edges. To check for a collision in 2D, you can check the sign of the perpdot (perpendicular dot product) of your starting point versus the collsion vector and the sign against the end point of your movement against the collision vector. If they are different, you crossed the line and a collision occured. If either are 0, you are on the collision line. Be sure to check for the end point of the line as well which involves a few more dot products.
The added benefit of this method is that it makes it really easy to 'slide' your character along walls when the collide instead of just backing them up to the previous position which causes wall sticking and vibration. It also is really really fast being just a few multiplies and subtracts. It also scales easily to SIMD style code as well.
See this question for a bit more info.
Your submarine is smaller than a tile, so the submarine will be covering at most 4 tiles at any given time.
Identify the tiles that the submarine overlaps. At least 1, at most 4.
For each overlapping tile, call a function that corresponds to that tile's type (0 through 6)
You can pass to each function how far the sub is from that tile's center.
Here's the easiest:
bool collided_with_tile_0( int x_offset, int y_offset )
{
return false; // Nothing to collide with
}
This one's pretty easy too:
bool collided_with_tile_1( int x_offset, int y_offset )
{
return std::abs( y_offset ) < SUB_SIZE; // Collision if y_offset is close to 0
}
Good luck!
Im working on a 2D game in which the terrain can vary and is composed of any shape of polygons except for self intersecting ones. The player collision box is in the shape of a square and can move about. My question is this: How do I keep an always-upright box to collide with variable terrain and always stay outside?
My current approach that I made up albeit no code yet works like the following:
The blue square is the player hitbox. First, it moves with a velocity downwards as an example. My goal is to find the heighest point in its travel path where it can be safely outside of the terrain polygon. I test all the terrain vertex points inside its travel path and project them to the velocity of the box. I take the farthest projection.
The farthest projection will be the max distance allowed to move in without going into the terrain.
Move the square by distance in the direction of velocity and done.
However, there are few scenarios that I encountered where this does not work. Take this as an example:
To remedy this situation, I now test for one corner of the square. If the distance from the corner is shorter than the farthest projection, then that distance will give the appropriate shift in distance. This pretty much makes the algorithm full-proof. Unless someone states another exception.
Im going a little crazy and I would appreciate feedback on my algorithm. If anyone has any suggestions or good reads about 2D upright box collisions on terrain or anything similar, that would be great.
This may be useful, and here I'll quickly elaborate on "upright" square collision.
First the collision may occur on the side of the square, and not necessarily a corner. A simple solution to check any collision is describe the region delimited by the square, and then check if any point of your uneven terrain is within this region.
To define the square region, assume your upright square is has the corners (x1,y1), (x2,y1), (x2,y2), (x1,y2), where x2>x1 and y2>y1. Then for a point (x,y) to be within the square it needs to satisfy the conditions
If( x1< x < x2 and y1< y <y2) Then (x,y) is in the square.
Then to conclude, all you need do is check if any point on the terrain satisfies the above condition.
Good luck.
I'm trying to do a mesh-to-circle collision system for my game. I've seen some examples where you iterate over all the verts of the mesh and check if they are inside the circle. But the problem is that sometimes the vertices are not inside the circle, but the lines that this vertices form are. In this cases, the collision check evaluates to false when it should evaluate to true. How can I make a good collision detection of this type? (in c/c++)
If you want you could calculate the distance from the line to the center of the circle. But I think it will be too costly. If the distance is lower than the radio you could have a collision. You will need to check if this part of the line is between the points.
Distance line to point
Actually, a quick google lets you know that this is a duplicate of a question already on stack overflow: Circle line-segment collision detection algorithm?
Just iterate over all the edges. And don't worry about the vertices: if a vertex is inside the circle, some edge is bound to cross it (unless the entire grid is inside the circle, which I'm guessing isn't likely).