|
|
On Wed, 2 Sep 1998 05:37:18 -0400, Duane Tackett <ddt### [at] junocom> wrote:
> Now that I have your attention (with the subject line) I have forgotten
>how to do something seemingly very basic: I nee to translate a line segment
>into x,y coordinates. What I need is a 5 sided regular polygon (pentagon in
>english) and I have forgotten the equation to convert this to x,y points.
> For instance, I want to have a 5 sided object with sides that are 2
>units in length. I have figured out that the degree of the angle between
>each side is 72 (360 degrees divided by 5 sides) but I can't remember the
>equation to translate this. I don't want the points, I want an explanation
>so I'll have one less silly question to ask. Let me know if you can help.
First, it will help to have the radius of the polygon rather than the length
of the side. For a polygon of n sides with side s, the radius is
r=(0.5*s)/sin(pi/n)
(assuming your sine function takes its arguments in radians. If it uses
degrees, use 180 instead of pi.) To explain this to yourself, consider the
isosceles triangle formed by two radii, plus the side between them. If you
draw a line perpendicular to the side, through the center of the triangle,
you have two right triangles with a hypotenuse of length r and one side of
length s/2. That side is opposite an angle of half the angle you calculated,
or 180 divided by the number of sides. The sine is the opposite divided by
the hypotenuse, or (s/2)/r, so r is the opposite divided by the sine.
Now, for points i numbered 0 to n-1 (for a pentagon, i is 0, 1, 2, 3, or 4)
you have:
x(i) = r*cos(2*pi*i/n)
y(i) = r*sin(2*pi*i/n)
Again, assuming you use radians. If you use degrees, substitute 180 for pi.
To justify these formulae to yourself, consider the case where i=1. Then
you have x(1)=r*cos(2*pi/n) and y(1)=r*sin(2*pi/n). 2*pi/n is the angle
between two points. In the case of a pentagon, it's 72 degrees. If you draw
the radius through point 1 (the first point counterclockwise from the point
that lies on the x axis) and then draw the x and y components of the radius,
you'll find that you have a right triangle. One of the angles in the right
triangle is the central angle with measure 2*pi/n. The hypotenuse is r.
Now you see that the vertical line, whose length is equal to y, is opposite
the angle of measure 2*pi/n, and the horizontal line, whose length is equal
to x, is adjacent. So knowing that the sine is the opposite over the
hypotenuse, you have that the opposite, or y, is the sine times the
hypotenuse. Similarly, since cosine is adjacent over hypotenuse, x is the
cosine times the hypotenuse.
Now that you understand the math that makes this all work, consider an
alternative in POV that can save you from having to understand at least
part of it. This code generates the points in the XZ plane, as with a torus,
but could easily be modified to put them in the XY plane instead.
#declare Sides=5;
#declare Length=2;
#declare Radius=(0.5*Length)/sin(pi/Sides);
#declare i=0;
#while (i < Sides)
#declare Point=vrotate( Radius * x, 360/Sides*i*y );
/* Do whatever you want with Point here. Maybe put it an an array. */
#declare i=i+1;
#end
Post a reply to this message
|
|