问题描述:

Hey guys this is a bit of a homework puzzle I'm working on and my trig isn't too strong so bear with me.

I have a list of three vertexes and I've already figured out how to calculate the internal angle where they meet (I'm using this to test to make sure they have a valid angle so the polygon is a valid polygon).

Currently I pluck out the three vertices in a row, then calculate the edges to the vertex I want the angle on, then get the acos of the vector product at that point:

`double dx21 = one.x - two.x;`

double dx31 = three.x - two.x;

double dy21 = one.y - two.y;

double dy31 = three.y - two.y;

double m12 = Math.sqrt(dx21*dx21 + dy21*dy21);

double m13 = Math.sqrt(dx31*dx31 + dy31*dy31);

double theta = Math.acos((dx21*dx31 + dy21*dy31)/ (m12 * m13));

I know nominally I could grab the external angle by subtracting the internal angle from 360 degrees, but this is a sanity check to make sure that the polygon is valid (The vertices are in counter clockwise order).

The note I was given was to make sure the sin of the vector product at the vertexes was positive, but I've been playing on this for a while on paper and am not really having any luck getting this to work.

I know it's mostly a maths question but any advice would be really useful.

Here are a few notes.

First, the external angle as it's usually defined would be 180 degrees - the interior angle, or pi - the interior angle, depending on your units. See here. A quick sanity check would be to add the external angles together to be sure you get a circle.

Second, you may know this but I should point out that Math.acos returns an angle in radians, not degrees.

Third, note that the cosine can't distinguish between a convex and a concave angle, which means that your interior angle method is only valid for convex polygons. You might be better off working with the cross product, which will give you the sine of the angle.

Finally, getting to your question, here's a hint: You look at the vectors from p2->p1 and p2->p3; when I read the problem, I pictured each the vectors from p1->p2 and p2->p3. Either one is a perfectly valid way to solve the problem, but think about how the angles between these pairs of vectors are different, and how that relates to your problem.

您可能感兴趣的文章：

- android - Rotate an image around center
- jquery - Is there any way to have a default invisible option that describes my `select` tag?
- java - Using Enabled Property on a JButton in netbeans
- cocoa - Doesn't initWithWindowNibName Set the window Field
- xcode - Importing .xls/.csv into an iPhone app
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?

随机阅读：

**推荐内容**-

**热点内容**-
- php - Reading a specific line from a text file
- clr - Any implementation of an Unrolled Linked List in C#?
- Finding Hudson Log Files
- Forward to a payment-gateway together with POST data using cURL (or any other PHP server side solution)
- WCF in Winforms app - is it always single-threaded?
- git svn - git svn fetch does not fetch a Subversion commit message modified after initial clone
- java me - Why I am getting the bad length exception when I am running this application?
- java - How to get string.format to complain at compile time
- ruby on rails - Trigger observer of parent class on change
- python - Issue with URL pattern in Django with webmonkey tutorial