von dp am 23.August 98 um 18:37:49:
>I want to increase the number of objects revolving around that center
>point. I want the ability to place 10, 17 or whatever number of objects
>it suits me and have them spaced evenly around the 360 degrees of that
>imaginary circle.
Hi Harding
I would break this problem down into two parts:
1) How to place an arbitrary number of objects at even distances around
a circle.
2) How to make the circle of objects rotate.
I'll answer the first part fully, and hope that this gives you enough
information for you to answer the second part yourself (since you already
have a handler to adapt).
You might like to get pencil and paper, a ruler and a compass, so that
you can draw the shapes I describe below.
RADIANS
Director uses radians to describe rotation round a circle.
Definition: a radian is the angle subtended at the centre of a circle by
an arc equal to the radius.
Explanation
Imagine an equilateral triangle, where all the sides are the same length
- let's say r units long. The angle at any corner will be 60°.
A sector is very like a triangle, except that one of the sides is curved.
The curved side is called an arc. Choose one corner of your equilateral
triangle to be the centre of a circle of radius r. This circle will pass
through the other two corners of the triangle. The arc between the two
points will be slightly longer than the straight line of the triangle.
Now, imagine that the triangle is squeezed slightly, so that the angle at
the centre of the circle is a little bit smaller. Imagine that the
opposite edge of the triangle is flexible, but that its length won't
change. As you squeeze the angle at the centre of the circle, so the
opposite side will curve out, until it is lying along the circumference
of the circle.
You now have a sector whose sides are all one radius long: two of the
sides are the radius of the circle, the other is an arc of the circle.
The angle at the centre of the circle, butween the two straight sides,
will now be a little less than 57.3°
This angle is known as a radian.
Since the circumference of a circle is 2 * pi times its radius, there
are 2 * pi radians in one complete revolution around a circle.
(The Babylonians divided a circle into 360°, because of their way of
reckoning the length of a year: 360 ordinary days + 5 holy days)
SINES, COSINES and TANGENTS
Imagine a right angled triangle, with the two shorter sides drawn
horizontally and vertically. Imagine a circle which has its centre at
one end of the longest side (the hypothenuse), and passes through the
other end of the hypothenuse. By Pythogoras' theorem, you can work out
the length of any side, given the other two. But what about the angles?
Lets call the centre of our circle 0 (for origin).
The SIN of the angle at 0 is equal to the length of the side opposite 0
divided by the radius of the circle (or hypothenuse). If the angle at O
s very small, the sine will be very small. If the angle at O is almost
a right angle, the sine will be almost 1.
The COS of the angle at 0 is equal to the length of the short side which
touches O divided by the radius of the circle (or hypothenuse). The
cosine of a small angle is almost 1.
The TAN of the angle at 0 is equal to the length of the side opposite
O divided by the length of the short side touching O. The tangent of a
small angle is almost the same as the sine. For an angle of 90° (¼/2),
the tangent is infinite.
The functions asin(), acos() and atan() convert the angle back to a
length.
So...
asin (sin (anAngle)) = anAngle
...and...
sin (asin (oppositeSideToHypothenuseRatio))=oppositeSideToHypothenuseRatio
POLAR COORDINATES AND loc
You can define the position of a point in relation to another point by
one of two means.
1) You imagine a line between the two points and a horizontal line
passing through one of them. You determine the angle between the two
lines, and the distance between them. This gives you two Polar
Coordinates: a distance and an angle
2) You determine how far to the right you must move from one of the points
in order to be directly above or below the other, then how far you must
move down to reach the second point (moving left or up means moving a
negative distance right or up). This gives you two Stage Coordinates:
a locH and a locV which describes the offset between the two points.
CONVERTING POLAR COORDINATES TO STAGE COORDINATES
In your case, you have a circle with a given central point. You want to
divide the circumference of this circle into n equal parts.
The circumference is 2 * pi * radius. Each part will be
((2 * pi) / n) * radius units long. The angle between each point will be
((2 * pi) / n radians. (Do you see the logic behind dividing the circle
into radians?)
Here's a handler to create the polar coordinates for each point, for a
circle centred at point (0, 0):
on polarCoordinates numberOfPoints, radius
set coordinatesList = []
set angle = (2 * pi()) / numberOfPoints
repeat with i = 1 to numberOfPoints
append (coordinatesList, [radius, angle * i])
end repeat
return coordinatesList
end
To convert a Polar Coordinate to Stage Coordinates, you must use SIN() and COS().
on stageCoordinates radius, angle
set h = radius * cos (angle)
set v = radius * sin (angle)
return point (h, v)
end
So to get a list of Stage Coordinates for n equally spaced points around a
circle with a given centre point:
on circleCoordinates numberOfPoints, radius, centre
set coordinatesList = []
set angle = (2 * pi()) / numberOfPoints
repeat with i = 1 to numberOfPoints
append (coordinatesList, stageCoordinates (radius, angle * i) + centre)
end repeat
return coordinatesList
end circleCoordinates
And to place your sprites on stage correctly:
on placeSprites numberOfPoints, radius, centre
set pointsList = circleCoordinates (numberOfPoints, radius, centre)
beginRecording
repeat with i = 1 to numberOfPoints
set theSprite to i +
set the member of sprite theSprite to member
set the loc of sprite theSprite to getAt (pointsList, i)
end repeat
endRecording
end placeSprites
Replace the words in as appropriate.
Cheers,
James
--
James and Emmanuelle Newton
D. Plänitz