![]() |
Freethought & Rationalism ArchiveThe archives are read only. |
![]() |
#1 |
Banned
Join Date: Sep 2001
Location: a place where i can list whatever location i want
Posts: 4,871
|
![]()
Say you're given two equal sets of numbers: one representing the lengths of lines and the other representing angle measures in degrees. Besides of drawing the polygon out, how can you be sure that the shape is fully enclosed? That is, just from the side lengths and angle measures, is there any formula that can be used to determine if a fully enclosed polygon can be made form them?
(For anyone who can tell why I'm asking this: yes, it would take too much time to redo all my shape classes to take in x,y coordinates instead of arrays of side lengths and angle measures, even though coordinates would guarantee an enclosed polygon. TOTALLY THINKING AHEAD WHEN I DESIGNED THEM, YESSIR.) |
![]() |
![]() |
#2 |
Obsessed Contributor
Join Date: Sep 2000
Location: Not Mayaned
Posts: 96,752
|
![]()
#1: Sum (180 - angle) for all angles. If the answer isn't 360 it won't work.
#2: For each segment get it's angle relative to zero. For all segments: x = sum(cos(angle)*length) y = sum(sin(angle)*length) If X <> 0 or Y <> 0 then it doesn't work. |
![]() |
![]() |
#3 | |
Veteran Member
Join Date: Apr 2001
Location: Heaven
Posts: 6,980
|
![]() Quote:
It's (n-2)180 degrees, where n=the total number of faces. For #2, you have to arrange them as vectors (yes, I know, boo, hiss), determine their x and y components, and then sum it. |
|
![]() |
![]() |
#4 |
Contributor
Join Date: Jul 2000
Location: Lebanon, OR, USA
Posts: 16,829
|
![]()
IMO, the simplest way is to calculate x,y coordinates from the line lengths and angles.
CumAng = 0; X = 0; Y = 0; for all side/angle sets: CumAng += (180d - Angle); X += Side*cos(CumAng); Y += Side*sin(CumAng); endfor If the shape is closed, then the final position will be (X=0,Y=0) -- the initial one. GunnerJ, it looks like you ought to redo your shapes classes with (x,y) coords; your side-angle approach leaves position and rotation undetermined, and it does not guarantee closure. |
![]() |
![]() |
#5 |
Banned
Join Date: Oct 2000
Location: Bloomington, MN
Posts: 2,209
|
![]()
Let X be the number of lines, and Y be the sum of the angle degrees. The polygon is enclosed if and only if X = (Y/180)+2.
I think. Dave |
![]() |
![]() |
#6 |
Banned
Join Date: Sep 2001
Location: a place where i can list whatever location i want
Posts: 4,871
|
![]()
lpetrich: You're right, a coordinate system would be the smart thing to do. But I'm really out of time. Maybe if I was thinking ahaead, I'd have realized that the best way to sonctruct these shape classes would be to have them take in an array of structs (containing x,y coordinates). But I didn't so I'm stuck.
Tap dancing: so, your formula is ((number of sides -2) * 180) - sum of angles, and if it doesn't equal 360, it's wrong? Silent Dave: I'll check this out too. Thanks all. |
![]() |
![]() |
#7 | |
Veteran Member
Join Date: Apr 2001
Location: Heaven
Posts: 6,980
|
![]() Quote:
Add up all of the angles. Now apply (n-2)180. If those two numbers are different, then it will not be enclosed. A pentagon, for example, has 540 degrees, whereas a triangle has 180. Only circles and paralellograms have 360 degrees in them. |
|
![]() |
![]() |
#8 | |
Veteran Member
Join Date: Apr 2001
Location: Heaven
Posts: 6,980
|
![]() Quote:
Add up all of the angles. Now apply (n-2)180. If those two numbers are different, then it will not be enclosed. A pentagon, for example, has 540 degrees, whereas a triangle has 180. Only circles and paralellograms have 360 degrees in them. |
|
![]() |
![]() |
#9 |
Banned
Join Date: Sep 2001
Location: a place where i can list whatever location i want
Posts: 4,871
|
![]()
OK, but how does this account for varying side lengths? Or is there no way to do this outside of x,y coordinates?
I guess I'm kind of confused about what Loren means by "angle relative to zero." How does the second forumla work? |
![]() |
![]() |
#10 |
Veteran Member
Join Date: Apr 2001
Location: Heaven
Posts: 6,980
|
![]()
You need x-y coordinates. Loren tells how to get there by way of his formula
What Loren means is the angle relative to a line that is drawn from nearby the object--either parallel with a base, or perpendicular to it (parallel is a much simpler option, by the way). By taking the cosine of the each angle and the side it coresponds to (do each side once, whichever angle should be fine), you arrive at the x component for that segment. The sine will give the y component. If you add the x components up, they should equal zero, and y components should simlarly combine to zero. Try this with a square. You have l*sin 90+l*sin 270 for the y components (which gives sum zero), and l*cos 0+l*cos 180 for the X components (which also gives zero).. |
![]() |
Thread Tools | Search this Thread |
|