Arbitrarily oriented minimum area bounding "box" of a polygon on a sphere - geometry

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.

Related

Compute points at a given geodesic distance on a mesh

Repeating this question for better visibility. I have a triangular mesh (assume a manifold mesh). I want to sample corners of a square on a mesh that is independent of the triangulation.
I am following these steps
Sample a triangle (based on the areas of the triangles)
Sample a point uniformly on the triangle/face
Sample a pair of random perpendicular directions
I want to calculate the distance of three other corners of the square given an edge length. Since the corners can be on any other face, the output should be of the format (Face, barycentric coordinates on that face).
I am looking at libraries such as Polyscope or pygeodesic that use the heat method to compute the geodesic distance between two vertices of the mesh, but I am not sure how to get points at an arbitrary geodesic distance from another point.

Determining a bounding polygon surrounding specific points

I've been trying to figure out how to determine a bounding polygon around a specific set of points (set A) from another set of points (set B) such that the polygon only contains points in set A. For simplicity, we can assume the polygon will be convex, set A will only include 2 points, and a solution will exist from the given data.
For example, given:
these points, I want to create a polygon around the blue points from the red points like this. This could be done by finding the next point with the greatest angle while not cutting through the blue points, but I don't want the result to be too minimal like this.
Any suggestions or algorithms for solving this problem?
Seems that if you calculate triangulation over all (red and blue) points, then triangles containing blue vertices, form the first approximation of needed region. This approximation usually would be concave, so one need to cut off "ears".
If result looks too small, it is possible to add the third vertices of outer border triangles if they don't violate convexity.

Finding the Dimension of OBJ objects

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.

Drawing a circular, minor arc given the centre point and two other points

Does anyone know how to draw a circular, minor arc given the centre point and two other points that lie on the circle?
I want to draw the pixels directly to the screen, and preferably, not have to calculate the angles.
I am using SDL and C, but may be OK studying code given that uses a different language.
Thanks.
All points on a circle are equal distance to the centre.
Given you know two points on the circle you can calculate this distance.
Assuming you have cartesian coordinates, for every x or y value between the known points calculate the other value so that the point is equal distance to the centre and plot these points.
I think this is conceptually the easiest way, though not the most efficient.

Subtract Rectangle from Polygon

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.

Resources