how to convert a near orthogonal-edge polygon to a mimum inbounding orthogonal-edge polygon? - geometry

Let's consider there is a polygon with near orthogonal edges that is in the range of (70, 89)° or (91, 110)°. We know the sum of angles in a polygon is multiple of 180°.
The question is how to convert a polygon with customized shape to a minimum polygon with right angles.
As a very simple case, let's consider the example below:
What we want to achieve is, the polygon below:
The number of edges can be more. The example above is just a simple example.

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.

How to calculate what percentage of a pixel is within the bounds of a shape

I have a 2d grid where pixel centers are at the intersection of two half-grid lines, as shown below.
I also have a shape that is drawn on this grid. In my case the shape is a glyph, and is described by segments. Each segment has a start point, end point and a number of off-curve points. These segments can be quadratic curves or lines. What's important is that I can know the points and functions that make up the outline of the shape.
The rule for deciding which pixels should be turned on is simple: if the center of the pixel falls within the shape outline, turn that pixel on. The following image shows an example of applying this rule.
Now the problem I'm facing has to do with anti aliasing. What I'd like to do is to calculate what percentage of the area of a given pixel falls within the outline. As an example, in the image above, I've drawn a red square around a pixel that would be about 15% inside the shape.
The purpose of this would be so that I can then turn that pixel on only by 15% and thus get some cleaner edges for the final raster image.
While I was able to find algorithms for determining if a given point falls within a polygon (ray casting), I wasn't able to find anything about this type of problem.
Can someone can point me toward some algorithms to achieve this? Also let me know if I'm going about this problem in the wrong way!
This sounds like an X, Y problem.
You are asking for a way to calculate the perecentage of pixel coverage, but based on your question, it sounds that what you want to do is anti alias a polygon.
If you are working only with single color 2D shapes (i.e red, blue, magenta... squares, lines, curves...) A very simple solution is to create your image and blur the result afterwards.
This will automatically give you a smooth outline and is simple to implement in many languages.

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.

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