geom2d | Objects and Algorithms for 2D Geometry in Ruby | 3D Animation library
kandi X-RAY | geom2d Summary
kandi X-RAY | geom2d Summary
This library implements objects for 2D geometry, like points, lines, line segments, arcs, curves and so on, as well as algorithms for these objects, like line-line intersections and arc approximation by Bézier curves.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculate a segment for the given segment .
- Add two bounds to this point
- Multiply Geometry
- Multiply a Point .
- Returns a new Point
- Adds a point to this segment .
- Returns the bounds of the given point .
- Yield each segment
- Determine whether the diagonal is a square
- Returns an array of all the boxes associated with this polygon .
geom2d Key Features
geom2d Examples and Code Snippets
Community Discussions
Trending Discussions on geom2d
QUESTION
I wish to find the shortest distance between a point and a polyshape
using the distancepointpolygon
function from Matlab geom2d
library.
The distancepointpolygon
function does it for polygon and therefore how can I convert any polyshape
to a N-by-2 array containing vertex coordinates? I did it manually and I am looking for a general solution.
ANSWER
Answered 2020-Jul-14 at 16:55polySquare.Vertices
should be the matrix you need:
QUESTION
I am reviewing some MATLAB code that is publicly available at the following location: https://github.com/mattools/matGeom/blob/master/matGeom/geom2d/orientedBox.m
This is an implementation of the rotating calipers algorithm on the convex hull of a set of points in order to compute an oriented bounding box. My review was to understand intuitively how the algorithm works however I seek clarification on certain lines within the file which I am confused on.
On line 44: hull = bsxfun(@minus, hull, center);
. This appears to translate all the points within the convex hull set so the calculated centroid is at (0,0). Is there any particular reason why this is performed? My only guess would be that it allows straightforward rotational transforms later on in the code, as rotating about the real origin would cause significant problems.
On line 71 and 74: indA2 = mod(indA, nV) + 1;
, indB2 = mod(indB, nV) + 1;
. Is this a trick in order to prevent the access index going out of bounds? My guess is to prevent out of bounds access, it will roll the index over upon reaching the end.
On line 125: y2 = - x * sit + y * cot;
. This is the correct transformation as the code behaves properly, but I am not sure why this is actually used and different from the other rotational transforms done later and also prior (with the calls to rotateVector). My best guess is that I am simply not visualizing what rotation needs to be done in my head correctly.
Side note: The external function calls vectorAngle
, rotateVector
, createLine
, and distancePointLine
can all be found under the same repository, in files named after the function name (as per MATLAB standard). They are relatively uninteresting and do what you would expect aside from the fact that there is normalization of vector angles going on.
ANSWER
Answered 2020-Mar-03 at 12:54I did not really look at the code, this is an explanation of how the rotating calipers work.
A fundamental property is that the tightest bounding box is such that one of its sides overlaps an edge of the hull. So what you do is essentially
try every edge in turn;
for a given edge, seen as being horizontal, south, find the farthest vertices north, west and east;
evaluate the area or the perimeter of the rectangle that they define;
remember the best area.
It is important to note that when you switch from an edge to the next, the N/W/E vertices can only move forward, and are readily found by finding the next decrease of the relevant coordinate. This is how the total processing time is linear in the number of edges (the search for the initial N/E/W vertices takes 3(N-3) comparisons, then the updates take 3(N-1)+Nn+Nw+Ne comparisons, where Nn, Nw, Ne are the number of moves from a vertex to the next; obviously Nn+Nw+Ne = 3N in total).
The modulos are there to implement the cyclic indexing of the edges and vertices.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install geom2d
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
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