packcircles | R package for circle packing | Computer Vision library
kandi X-RAY | packcircles Summary
kandi X-RAY | packcircles Summary
R package for circle packing. Algorithms to find arrangements of non-overlapping circles. This package provides functions to find non-overlapping arrangements of circles. The function circleRepelLayout attempts to arrange a set of circles of specified radii within a rectangle such that there is no-overlap between circles. The algorithm is adapted from an example written in Processing by Sean McCullough (which no longer seems to be available online). It involves iterative pair-repulsion, in which overlapping circles move away from each other. The distance moved by each circle is proportional to the radius of the other to approximate inertia (very loosely), so that when a small circle is overlapped by a large circle, the small circle moves furthest. This process is repeated iteratively until no more movement takes place (acceptable layout) or a maximum number of iterations is reached (layout failure). To avoid edge effects, the bounding rectangle is treated as a toroid. Each circle's centre is constrained to lie within the rectangle but its edges are allowed to extend outside. The function circleProgressiveLayout arranges a set of circles, which are denoted by their sizes, by consecutively placing each circle externally tangent to two previously placed circles while avoiding overlaps. It was adapted from a version written in C by Peter Menzel. The underlying algorithm is described in the paper: Visualization of large hierarchical data by circle packing by Weixin Wang et al. (2006). The function circleRemoveOverlaps takes an initial set of overlapping circles and attempts to find a non-overlapping subset or, optionally, a subset with some specified degree of overlap. Circle positions remain fixed. It provides several fast heuristic algorithms to choose from, as well as two based on linear programming. For the latter, package lpSolve must be installed. The function circleGraphLayout is an initial Rcpp port of an algorithm described by Collins and Stephenson (2003) to find an arrangement of circles which corresponds to a graph of desired circle tangencies. The implementation is based on a Python version by David Eppstein (see CirclePack.py in the PADS library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of packcircles
packcircles Key Features
packcircles Examples and Code Snippets
Community Discussions
Trending Discussions on packcircles
QUESTION
(Working in 2d for simplicity) I know that the force exerted on two spherical bodies by each other due to gravity is
G(m1*m2/r**2)
However, for a non-spherical object, I cannot find an algorithm or formula that is able to calculate the same force. My initial thought was to pack circles into the object so that the force by gravity would be equal to the sum of the forces by each of the circles. E.g (pseudocode),
ANSWER
Answered 2020-Jan-20 at 22:36Some of this explanation will be somewhat off-topic but I think it is necessary to help clarify some of the things brought up in the comments and because much of this is somewhat counterintuitive.
This explanation of gravitational interactions depends on the concept of point masses. Suppose you have two point masses which are in an isolated system separated from each other by some distance, r1, with masses of m1 and m2 respectively,
The gravitational field created by m1 is given by
where G is the universal gravitational constant, r is the distance from m1 and r̂ is the unit direction along the line between m1 and m2.
The gravitational force exerted on m2 by this field is given by
Note - Importantly, this is true for any two point masses at any distance.1
The field nature of gravitational interactions allows us to employ superposition in calculating the net gravitational force due to multiple interactions. Consider if we add another mass, m3 to the previous scenario,
Then the gravitational force on mass m2 is simply a sum of the gravitational force from the fields created by each other mass,
with ri,j = rj,i. This holds for any number of masses at any separations. It also implies that the field created by a collection of masses can be aggregated by a vector sum, if you prefer that formalism.
Now consider if we had a very large number of point masses, M, aggregated together in a continuous, rigid body of uniform density. Then we wanted to calculate the gravitational force on a single spatially distinct point mass, m, due to the aggregate mass, M:
Then instead of considering point masses we can consider areas (or volumes) of mass of differential size and either integrate or sum the effect of these areas (or volumes) on the point mass. In the two dimensional case, the magnitude of the gravitational force is then
where σ is the density of the aggregate mass.2 This is equivalent to summing the gravitational vector field due to each differential mass, σdxdy. Such equivalence is critically important because it implies that for any point mass far enough outside of a mass distribution, the gravitational force due to the mass distribution is almost exactly the same as it would be for a point mass of mass M located at the center of mass of the mass distribution.3 4
This means that, to very good approximation, when it comes to calculating the gravitational field due to any mass distribution, the mass distribution can be replaced with an equivalent-mass point mass at the center of mass of the distribution. This holds for any number of spatially distinct mass distributions, whether those distributions constitute a rigid body or not. Furthermore, it means that you can even aggregate groups of distributions into a single point mass at the center of mass of the system.5 As long as the reference point is far enough away.
However, in order to find the gravitational force on a point mass due to a mass distribution at any point, for any mass distribution in a shape and separation agnostic manner we have to calculate the gravitational field at that point by summing the contributions from each portion of the mass distribution.6
Back to the questionOf course for an arbitrary polygon or polyhedron the analytical solution can be prohibitively difficult, so it is much simpler to use a summation, and algorithmic approaches will similarly use a summation.
Algorithmically speaking, the simplest approach here is not actually to use geometric packing, either using circles/spheres or squares/cubes. It's not impossible to use packing, but mathematically there are significant challenges to that approach - it is better to employ a method which relies on simpler math. One such approach is to define a grid encompassing the spatial extent of the mass distribution, and then create simple (square/cubic or rectangular/cuboidic) polygons or polyhedrons with the grid points as vertices. This creates three kinds of polygons or polyhedrons:
- Those which do not encompass any of the mass distribution
- Those which are completely filled by the mass distribution
- Those which are partially filled by the mass distribution
This will work well when the distance from the reference point to the mass distribution is large relative to the angular extent of the distribution, and when there is no geometric enclosure of the reference by the mass distribution (or by any several distributions).
You can then find the center of mass, R of the distribution by summing the contributions from each polygon,
where M is the total mass of the distribution, ri is the spatial vector to the geometric center of the ith polygon, and mi is the density times the portion of the polygon which contains mass (i.e. 1.00 for completely filled polygons and 0.00 for completely empty polygons). As you increase the sampling size (the number of grid points) the approximation for the center of mass will approach the analytical solution. Once you have the center of mass it is trivial to calculate the gravitational field created: you simply place a point mass of mass M at the point R and use the equation from above.
For demonstration, here is an implementation of the described approach in two dimensions in Python using the shapely library for the polygon operations:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install packcircles
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page