I am developing a web app and I need to find a way to draw an outline rectangular polygon connecting the given points to form a perimeter on a coordinate system.
I found this ordering shuffled points that can be joined to form a polygon (in python)
to be quite relevant to my problem, but it has the problem that, if any points surpasses the center of the polygon the algorithm does not work...
To make it more clear what I want I am attaching two pictures to show what I want to achieve with given points:
Correct way to join points
Wrong way to connect points
Is there an algorithm that given point coordinates creates the rectangular perimeter as I want it? Thanks
Related
I'm curious how one would deduce 3D coordinates in simple isometric images.
The only approach I could come up with is to do depth-first searches to find the vertices of each face and then use complex branching logic to figure out the vertex position from all the possibilities there are for how faces can be partially hidden. What would be a better approach to go about this?
This is just for hobby, so I'm fine with simplifying the problem further (say by requiring the scene to be composed of only unit voxels or by giving the solution only as coordinates of the midpoints of individual voxels instead of giving the coordinates and their face indices in counter-clockwise order).
I'd assume the input to be given as a matrix of the five different colors I use in the picture. As output I'd expect a list of 3D coordinates, possibly accompanied by a list of coordinate indices for the faces.
I assume that you are able to detect all edges and their direction (among six possilbe). Also if they are complete or occluded. And detect the vertices, so that you get a 2D graph.
Assign the coordinates (0, 0, 0) to some point, such as the lowest vertex. Then following every complete edge from the already known points, you will obtain the coordinates of the endpoints by considering the edge direction (and possibly length) and you will know which coordinate to increment/decrement.
In the end, you will get all coordinates of the endpoints of the complete edges, tell the complete faces, and be able to tell the occluded faces.
I'm trying to find out the 3D points of a point cloud which are inside a 3D Box. I'm able to get the points inside 3D box by the below logic, only when the 3d box is align with the axis, but on rotating the 3d box, the logic fails.
(This only applies if the box's edges are aligned with the coordinate axes.)
If the vertices are (x1,y1,z1),(x2,y1,z1),(x1,y2,z1),⋯,(x2,y2,z2), then any point (x,y,z) is inside the box if and only if
x1<x<x2
and
y1<y<y2
and
z1<z<z2
In other words, the point's coordinates are between the vertices' coordinates.
Now I got algo from https://math.stackexchange.com/questions/2909812/points-inside-a-3d-rectangle?noredirect=1&lq=1 but not able to figure out how to take the "position vectors".
Any suggestions!!
Another issue: Is there any fast way to find out all the points inside a 3D box, rather than iterating over the whole point cloud.
Any suggestion is appreciated!!!
Since you listed point-cloud-library in the question's tags, pcl::CropBox is probably what you are looking for. You basically provide the two corner points, a translation and a rotation, after that, you can extract all points inside the box.
I'll use the notation $\vec{OA}=\vec A-\vec O$ for a difference of position vectors. $O$ is one vertex, and $A,B,C$ are its three adjacent vertices.
O,A,B,C in there are vertices of cuboid. Being a parallelepiped, cube can defined by three adjacent faces, that's four points in total.
I am trying to write a Rigid body simulator, and during simulation, I am not only interested in finding whether two objects collide or not, but also the point as well as normal of collision. I have found lots of resources which actually says whether two OBB are colliding or not using separating axis theorem. Also I am interested in 3D representation of OBB. Now, if I know the axis with minimum overlap region for two colliding OBB, is there any way to find the point of collision and normal of collision? Also, there are two major cases of collision, first, point-face and second edge-edge.
I tried to google this problem, but almost every solution is only detecting collision with true or false.
Kindly somebody help!
Look at the scene in the direction of the motion (in other terms, apply a change of coordinates such that this direction becomes vertical, and drop the altitude). You get a 2D figure.
Considering the faces of the two boxes that face each other, you will see two hexagons each split in three parallelograms.
Then
Detect the intersections between the edges in 2D. From the section ratios along the edges, you can determine the actual z distances.
For all vertices, determine the face they fall on in the other box; and from the 3D equations, the piercing point of the viewing line into the face plane, hence the distance. (Repeat this for the vertices of A and B.)
Comparing the distances will tell you which collision happens first and give you the coordinates of the first meeting point (in the transformed system, the back to absolute coordinates).
The point-in-face problem is easy to implement as the facesare convex polygons.
I have a list of coordinates (latitude, longitude) that define a polygon. Its edges are created by connecting two points with the arc that is the shortest path between those points.
My problem is to determine whether another point (let's call it U) lays in or out of the polygon. I've been searching web for hours looking for an algorithm that will be complete and won't have any flaws. Here's what I want my algorithm to support and what to accept (in terms of possible weaknesses):
The Earth may be treated as a perfect sphere (from what I've read it results in 0.3% precision loss that I'm fine with).
It must correctly handle polygons that cross International Date Line.
It must correctly handle polygons that span over the North Pole and South Pole.
I've decided to implement the following approach (as a modification of ray casting algorithm that works for 2D scenario).
I want to pick the point S (latitude, longitude) that is outside of the polygon.
For each pair of vertices that define a single edge, I want to calculate the great circle (let's call it G).
I want to calculate the great circle for pair of points S and U.
For each great circle defined in point 2, I want to calculate whether this great circle intersects with G. If so, I'll check if the intersection point lays on the edge of the polygon.
I will count how many intersections there are, and based on that (even/odd) I'll decide if point U is inside/outside of the polygon.
I know how to implement the calculations from points 2 to 5, but I don't have a clue how to pick a starting point S. It's not that obvious as on 2D plane, since I can't just pick a point that is to the left of the leftmost point.
Any ideas on how can I pick this point (S) and if my approach makes sense and is optimal?
Thanks for any input!
If your polygons are local, you can just take the plane tangent to the earth sphere at the point B, and then calculate the projection of the polygon vertices on that plane, so that the problem becomes reduced to a 2D one.
This method introduces a small error as you are approximating the spherical arcs with straight lines in the projection. If your polygons are small it would probably be insignificant, otherwise, you can add intermediate points along the arcs when doing the projection.
You should also take into account the polygons on the antipodes of B, but those could be discarded taking into account the polygons orientation, or checking the distance between B and some polygon vertex.
Finally, if you have to query too many points for that, you may like to pick some fixed projection planes (for instance, those forming an octahedron wrapping the sphere) and precalculate the projection of the polygons on then. You could even create some 2d indexing structure as a quadtree for every one in order to speed up the lookup.
The biggest issue is to define what we mean by 'inside the polygon'.
On a sphere, every polygon (as long as the lines are not intersecting) defines two regions of the sphere. Both regions are equally qualified to be called the inside of the polygon.
Consider a simple, 1-meter on a side, yellow square around the south pole.
You can think of the yellow area to be the inside of the square OR you can think of the square enclosing everything north of each line (the rest of the earth).
So, technically, any point on the sphere 'validly' inside the polygon.
The only way to disambiguate is to select which side of the polygon you want. For example, define the interior to always be the area to the right of each edge.
I need an algorithm for splitting a (convex) polygon (let's call it base polygon). The polygon should be splitted into several smaller polygons by another polygon's edges (let's call this one the splitting polygon).
I know there exist algorithms for clipping a polygon (f.e. the Sutherland-Hodgman algorithm), but these algorithms discard the vertices that are lying outside of the splitting polygon instead of creating new polygons with them. I don't want to clip a polygon, i want to split it into several small parts.
I know the answer seems quite obvious because I would just have to extend the existing algorithms.
The problem is that I can't figure out a nice and performant way of doing this.
Are there existing algorithms that describe how to best split a polygon in a performant way?
There has to be a simple solution for this problem that I can't figure out at the moment.
You can see this problem as that of finding the intersection of the subject polygon and the complement of the window polygon. So you can use the standard Surtherland-Hodgman algorithm for that purpose, taking two precautions:
swap the roles of the subject and the window (actually your window is not convex as you consider its complement, only the subject is convex),
embed the window polygon in a large bounding box that covers both polygons, and consider the box as a polygon with a hole.
Example: the subject polygon is the rectangle and the window is the pentagon. Form the green polygon (larger rectangle with a hole) and clip it inside the rectangular (convex) window. The result of the clipping is in blue.
With some extra care, it should be possible to do without the large bounding box.