algorithm for filling shape A with shape B - computer-vision

I have been asked for giving an efficient algorithm for filling shape A with shape(s) B. For example, given a triangle, suggest an efficient algorithm for filling it with circles, so that we will get the best coverage.
What is the best way to solve this problem?

Related

Does AStar grid algorithm only handle square grids?

Looking for some clarification as I cannot seem to get an answer. When writing an astar algorirthm for grids, I was wondering if it was meant to work with any size rectangle or just perfectly square grids?
If there is a specific method for handling the heuristic for rectangles, what is it?
If people need to know I’m writing it in C++ for use in UE4.
Thanks everyone!
No, A* doesn't need a grid at all. You can use any placement of nodes, and as long as your heuristic is admissible, A* should work.
In fact, if you can guarantee your heuristic is admissible (i.e., it is guaranteed to never overestimate the distance), your nodes don't actually need a position at all. Of course, many actual applications do have nodes with particular locations, and Euclidean distance is a convenient admissible heuristic.
The only thing you need to do to make a rectangular grid work is to make sure your metrics are correct. That is: your node-to-node distances and your Euclidean distance calculation must correctly reflect the horizontal and vertical spacing of your grid.

Sorting a C++ vector based on an adjacency matrix

I have a vector e whose elements are indices to edges in a 2D (surface) mesh. For whatever reason, I would like to reorder this vector, so that each edge is surrounded by edges that are closest to it (basically, similar to what the asker is trying to achieve in this question).
I don't need it to be an exact or perfect solution (there probably isn't one), but I'd like to get as close as possible.
Here are the steps I have taken:
Create an adjacency matrix B for the mesh edges,
Use an algorithm such as RCM to get a reordering of the adjacency matrix to reduce its bandwidth (I'm using Petsc's MatGetOrdering to do this),
Apply the new ordering to get a new, reshuffled adjacency matrix, B2.
At this point, I would like to reorder the original vector e of mesh edges, to get a new vector e2 whose adjacency matrix is now B2.
Is this possible? i.e. is there enough information above to achieve this?
Is this a good approach to do what I'm trying to achieve?
If not, what would be the most sensible and robust approach? (e.g. I was also playing around with trying to do this based on physical distances rather than edge connectivity, but I'm not sure which approach is more realistic / sensible / robust),
If yes, how do I accomplish the last step of reordering the edge vector based on the new adjacency matrix?
I'm fairly new to Stack Exchange so please let me know if I should be asking this on another sub-community. I am also fairly new to graph theory, so I may be missing something obvious.
Thanks!

how can I get if a QPolygon is simple? [duplicate]

For a polygon defined as a sequence of (x,y) points, how can I detect whether it is complex or not? A complex polygon has intersections with itself, as shown:
Is there a better solution than checking every pair which would have a time complexity of O(N2)?
There are sweep methods which can determine this much faster than a brute force approach. In addition, they can be used to break a non-simple polygon into multiple simple polygons.
For details, see this article, in particular, this code to test for a simple polygon.
See Bentley Ottmann Algorithm for a sweep based O((N + I)log N) method for this.
Where N is the number of line segments and I is number of intersection points.
In fact, this can be done in linear time use Chazelle's triangulation algorithm. It either triangulates the polygon or find out the polygon is not simple.

How to make a given matrix diagonally dominant in c++?

Now for the Jacobi and Gauss-Seidel methods to work the matrix needs to be diagonally dominant. Any help would be appreciated.
Its different than making a matrix diagonal. //Because of the downvotes
There is really nothing you can do. If matrix don't satisfy conditions of some method, use other methods that can be applied to this matrix.
Remember, in such bad cases you can use Gauss Elimination to solve SLAE.

Spline fitting - Douglas-Peucker algorithm

I am planning on using the Douglas-Peucker algorithm for point reduction (unless someone knows of a better example). The data is 1D and the curve being constructed is 2D
Give a reduced hull of points I need a spline that will travel through all the points (I think Lagrange interpolation does this)
The main objective is to solve the tangent handles on something like a hermite curve so that the spline matches the original data curve as closely as possible.
Does anyone know of a an approach to this kind of problem?
Did you solve this? A spline that travels through your points is easily constructed as a Catmull-Rom spline (which map to Bezier curves, but represent the interpolation differently).