As an input, I receive some planar, triangulated geometry. Now, I need to compute the four coordinates of the corners of the bounding rectangle. Any Ideas?
I'm going to assume that you mean 2D space in the question title, because everything else refers to 2D.
Go through all the vertices (x,y) in your geometry, and calculate the maximum and minimum of the x's, and the max and min of the y's.
Then the vertices of your bounding rectangle will be (min_x,min_y), (max_x,min_y), (max_x, max_y), and (min_x, max_y).
Related
Is there a way to calculate maximum distortion error caused by the usage of spherical coordinates as if they were Cartesian?
More specifically max distance error of using straight line edges on equirectangular projection connecting points of a polygon on the surface of the earth vs. actual great circle lines connecting these points.
I have a Morton index that is using lat/lon coordinates and would like to get relevant ranges for doing point in polygon check. So, I would like to buffer the polygon by the maximum error distance when calculating the relevant Morton ranges. False positives (point not in polygon is included) are OK, but not false negatives (point in polygon is not included) are not.
Let's say I have a polygon specified by a set of vertices.
In addition, I also have a defined "starting point" that could be anywhere in the polygon.
How could I find the largest square, centered at the starting point, that fits completely within the polygon?
How about finding the largest x,y aligned distances from vertices to the start point?
If you also consider the sign of the distance you get the maximun +x,-x size and +y,-y size
The size of the square is limited by either one of its sides hitting a vertex of the polygon or one of its corners hitting a side of the polygon.
If rotation is not allowed,
find the shortest horizontal or vertical distance from the target point to the vertices;
find the closest intersections of the main bissectors through the target point and the polygon outline.
Keep the smallest square so defined.
If rotation is allowed, the problem is more difficult.
I am having a Three OBJ file, Cone, Sphere and Cube. How can I find the dimension of these objects, so that I can use it in my collision detection class?
i.e How can I find Radius, Length of Cube and Radius and Height of cone? Or is there any better way for collision detection, I have hundreds of random particle in my game which may or may not collide with these objects.
Length of the cube would be the distance of two consecutive points in one face.
If by radius of a cube you mean its diagonal it would be sqrt{3} of its length.
For a sphere, you can find its center by averaging all the vertices.
Its radius would be the distance between any vertex and the center.
It works fine if the sphere is not high resolution.
Otherwise, you have to solve a system of equations to find the sphere that passes through four points. You can take a look at this:
https://www.quora.com/How-do-you-find-the-center-and-radius-of-a-sphere-given-any-four-arbitrary-points-x_1-y_1-z_1-x_2-y_2-z_2-x_3-y_3-z_3-x_4-y_4-z_4
For the cone: there is probably one vertex that is connected to all other vertices. This vertex is probably easy to find for you. Let's call that p.
Take three vertex other than p. Find the circle passing through those vertices. Call that c. The distance between p and c is the height. The distance between c and any vertex other than p would be the radius. To find the circle passing through three points, you again need to solve a system of equations with three unknowns. As the equation of a circle is (x-a)^2+(y-b)^2=r^2. You need to put the values of your three points in the equation and find a,b, and r. Note that this equation assumes that the circle is in 2D. To use it for 3D, you need to first find the plane passing through these three points. If you do not want to go through all these. you can again average all vertices except p and find the center of the circle. the radius would be the distance between the center and any point. I actually assumed that the circles and spheres in your input are uniformly sampled which is the case for most of the available Obj files for these shapes.
I would like to calculate an arbitrarily oriented minimum (area) bounding box of a polygon on a sphere (as a simplification of Earth).
For an axis-aligned version I found the great example from Jason Davies.
The idea is to have as input a list of lon/lat coordinates for the points of the polygon and as output the coordinates of the 4 points (lon/lat) of the bounding box.
Bonus: consider the (very likely) cases where the polygon crosses the antimeridian, contains one pole and/or spans more than one hemisphere.
I'm looking for an algorithm that will subtract a rectangle from a simple, concave polygon and return a remainder of polygons. If the rectangle encloses the polygon, the remainder is null. In most cases, it looks like at least one edge will be shared between the rectangle and the polygon.
I've been digging around the internet, but I've not found a good lead.
Can someone point me in the right direction?
That's easy: Find the intersections between the rectangle and the edges of the simple polygon and cut the segments there. This does not require a spatial search structure as the 4 edges of the polygon are a constant factor, so that runs in linear time.
Then compute a constrained Delaunay triangulation of all segments and use seed points to grow the regions. Combine the regions appropriately (the triangles inside the simple polygon minus the ones inside the rectangle minus triangles outside. The triangles that remain are your result and the border edges are the edges of the resulting polygon.
Edit: I'm sorry if the answer was too short. The figure below shows the idea.
a) The two input polygons
b) The CDT after insertion of the (cutted) segments
c) The grown regions
d) The green region minus the red region
e) The border edges of the region of d.