Get angle for ear clipping - polygon

I am trying to implement a ear clipping algorithm into a program of mine but I am having issues. While that I can get it to work in a lot of situations, I haven't found a good way to check for reflex angles.
I've been looking up ways - every method I've tried to date seems to have angle it won't work for. When I try to find more information, most people's tutorials/work just tell me to "find the reflex angle and test for ear" then describe how to test for ear but not how to get the reflex angle.
Can anyone tell me how to get the proper angle inside the triangle for a concave polygon, or point me in the right direction? Could be an understanding issue with me. Thanks.

Figured out my problem was one of how I was conceiving the issue. I was saying that if the point was outside the polygon it could still be in the polygon without adding in my head the fact I removed the last vertex. Been busting my brains trying to implement ear clipping for a few days and got it wrong at this point - the solution was the basic "check if the center point of the triangle was outside the polygon and mark it as reflex".

Related

How to find the sides of a rectangle if you know the sides of a quadrilateral inside the rectangle?

I'm working on an application that uses a accelerometer to measure the sides of a room, I know it will not be exact measurements but it's fine.
In reality I would like the program to be able to calculate the sides of any room shape not only rectangles and squares (and more than 4 corners), but I'm starting with something more simple (rectangle shaped rooms).
My problem is not with the accelerometer but more with the math aspect of the code. Because I measured the room by placing the phone on a wall and then going to the connected wall, I will get the measurements of a quadrilateral inside the rectangle. From there, if it's possible, I will get the measurements of the sides of the rectangle, but I don't really know how.
What I've tried so far:
Divided the quadrilateral inside the rectangle in half, to make 2 triangles. Then I calculated the diagonal using the Pythagoras theorem. Then I used the law of Cosines to calculate one of the angles, and did the same again to find another. Then found the 3rd angle using the 2 other angles (c=a+b-180). I did this for both triangles.
I don't know if this is the right approach and if I have missed something simple, or if I simply don't have enough information to solve for the sides of the rectangle. I have looked into some geometry and trigonometry math online and haven't find anything that gives me a solution. But like I said, maybe I missed something simple.
Any push in the right direction would be helpful.
The rectangle and the quadrilateral
The problem lacks a unique solution. Imagine placing a pair of calipers around the quadrilateral. You'll be able to rotate the calipers around it, and at each angle the calipers will be able to close to a different width. Each of those widths is a different possible room dimension.
You'll also never get an accurate position measurement using the inertial sensors in a phone to begin with. The accels and gyros aren't even close to accurate enough. GPS is, but only outdoors away from structures that cause multipathing artifacts. Quick and sloppy with a tape measure will win every time.

Ue4 TiledMap Generation in 3d

How i can generate a Island shaped 2d Map with tiled cubes? Does someone can give me tipps or links or some other help please?
I already tried it with Noise but it ends in weird results cause i dont get how i use it in a 2d way.
Also i tried to give each tiles numbers so i knew what was the last placed tile.
But that ended in a big Chaos.
What i dont understand right now is how to "move" in that grid or how to know what was last and what could be the next and ye.
I really guess there is a simple way to handle that all which i dont realize at the moment?
I work for right now only with BP.
Thanks

SVG - Maths behind rounded corners with A/a or C/c

As I delve into SVG, I find myself trying to round corners in <path>s.
Contemplating web examples and looking at the answers to similar but more specific questions, I see that the most common ways to do so are using curves or arcs of some sort.
The idea behind arcs (A/a) seems pretty straight forward, but a blog post on how to figure out the maths was nowhere to be easily found or in not well-organized websites.
After seeing examples that use C/c I was pretty lost, and I couldn't find a well formatted and united blog post.
The world would be greatful if there was an SO answer with a few resources on nice posts for rounding edges or explaining the maths and implementation directly
The answer should assume:
no libraries (maybe as extra references, but not library-only answers)
paths with corners at non-orthogonal angles (non-90deg)
how it would be easier at certain specific angles/lengths
differences in efficiency between using arcs and curves (which one is best size-wise to use for what purpose and in what case)
generic examples (specific but not-hard-to-visualize values, out of 100 for example, are fine)
The answer can just list well-presented and introduced resources, and need to explain what is expected to find in the link along with a short description and summary
What maths are you trying to figure out?
Assuming you want "round" corners, meaning circular, then in most cases arcs will be what you want to use. And it has the advantage that there is normally no maths to figure out. You will have the start point of the arc (where the incoming path segment stopped). Then to add an arc, you just need to provide it with:
the radius of the curve you want
the rotation of the arc relative to the X axis. This will be 0 for circular arcs, and therefore for your case also.
the large arc flag. For every arc there will be two potential arcs: the shortest arc between the two points, or the "long way" around the circle
the sweep flag. This is the direction: clockwise or anti-clockwise
the end point of the arc
All pretty straightforward really. You may need some maths to work out where the end of the arc will be, but that's pretty much it.
The full explanation for all these parameters to the A command can be found in the Paths section of the SVG spec.
https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands

Collision detection with oddly shaped polygons

I am planning to make a program which will have some circular shapes moving inside of a oddly shaped Polygon.
I can't seem to figure out how to do the collision detection with the edges and have the shapes bounce back correctly.
I am sure this problem has been solved before, but I can't find a nice example.
My main problems are:
Figuring out if the circle has hit the edge of its surrounding polygon.
Once a hit occurs calculate the normal of the hit point to figure out the reflection vector.
Can anyone point me in the right direction?
Thanks, Jason
You need to do a circle line intersection test.
To make it faster, you can first check the bounding boxes. For example, if the start and end point of the line are both to the left of the leftmost coordinate of the circle, there can't be an intersection.

Find X/Y/Z rotation angles from one position to another

I am using a 3D engine called Electro which is programmed using Lua. It's not a very good 3D engine, but I don't have any choice in the matter.
Anyway, I'm trying to take a flat quadrilateral and transform it to be in a specific location and orientation. I know exactly where it is supposed to go (i.e. I know the exact vertices where the corners should end up), but I'm hitting a snag in getting it rotated to the right place.
Electro does not allow you to apply transformation matrices. Instead, you must transform models by using built-in scale, position (that is, translate), and rotation functions. The rotation function takes an object and 3 angles (in degrees):
E.set_entity_rotation(entity, xangle, yangle, zangle)
The documentation does not speficy this, but after looking through Electro's source, I'm reasonably certain that the rotation is applied in order of X rotation -> Y rotation -> Z rotation.
My question is this: If my starting object is a flat quadrilateral lying on the X-Z plane centered at the origin, and the destination position is in a different location and orientation where the destination vertices are known, how could I use Electro's rotation function to rotate it into the correct orientation before I move it to the correct place?
I've been racking my brain for two days trying to figure this out, looking at math that I don't understand dealing with Euler angles and such, but I'm still lost. Can anyone help me out?
Can you tell us more about the problem? It sounds odd phrased in this way. What else do you know about the final orientation you have to hit? Is it completely arbitrary or user-specified or can you use more knowledge to help solve the problem? Is there any other Electro API you could use to help?
If you really must solve this general problem, then too bad, it's hard, and underspecified. Here's some guy's code that may work, from euclideanspace.com.
First do the translation to bring one corner of the quadrilateral to the point you'd like it to be, then apply the three rotational transformations in succession:
If you know where the quad is, and you know exactly where it needs to go, and you're certain that there are no distortions of the quad to fit it into the place where it needs to go, then you should be able to figure out the angles using the vector scalar product.
If you have two vectors, the angle between them can be calculated by taking the dot product.

Resources