[Closed] Interior Angles
how to find all the interior angles of a concave polygon via maxscript? here is a java applet that does the same:
http://www.mathopenref.com/polygoninteriorangles.html
any help is appreciated
thanks!
First of all you need to get the face you want, get all it’s vertices, create vectors between all the vertices, and calculate the acos of the dot product of these vectors.
This is better described in the maxscript help file under “Frequently Asked Questions -> Practical Questions -> Working With Vectors -> How do I find the angle between 3 vertices?”
I wrote this once as practice, I will see if I can find it anywhere.
thanks for the post!
maybe the picture will help understand the problem…
the problem is how do i figure out weather the computed angle is an interior angle or not? [see the pic above]
any help is appreciated
thanks!
I’m trying to think how I went about this. You need an up vector I think that determines where the top of the shape is. For sake of this test we will call that Z.
Calc the angle as you have been, then build a third vector to compare to the first to get the direction of angle. So…
angle=what you are doing
vX=normalize c-b
vZ=[0,0,1]
vY=normalize (cross z x)
directionOfAngle=dot vX vY
if directionOfAngle<0 do angle=360-angle
That work for you.
thanks for the post !
i wanted to know the algorithm to compute interior angles of a polygon. To write a small class in java on polygons, as my project on computational geometry.
The solution i found out is similar to the one you have posted. credit : http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm . since i am working on this in java. the input available is just a set of points that make up the polygon and the winding of the polygon CW or CCW.
n = number of points in the polygon, here is the algorithm (actually the java implementation)
for(i=0;i<n;i++){
j = (i+1)%n;
k = (i+2)%n;
// same as a - b (picture in the previous post)
vector v1 = new vector(p[i].x-p[j].x, p[i].y-p[j].y, 0);
// same as c - b (picture in the previous post)
vector v2 = new vector(p[k].x-p[j].x, p[k].y-p[j].y, 0);// same as c -b
v1 = vector.normalize(v1);
v2 = vector.normalize(v2);
float cross = vector.cross(v1, v2);
float angle =Math.toDegrees(Math.acos(vector.dot(v1, v2)));
if(cross<0){
angle = 360 - angle;
}
System.out.println(cross + " " + Math.abs(angle));
}
thanks for the reply!