Although the question has already been solved, this is something I made
for fun in case the origin is offset. It should work if you paste it
into the actions panel for frame one and push ctrl+enter
function pointOnCircle(degree:Number, hyp:Number, oX:Number = 0,
oY:Number = 0):Point {
/*
degree is of course the angle in degrees
hyp = distance from origin = radius
oX, oY are the origins x and y offset values
*/
//radian = degree*180/pi
var radian:Number = degree * 0.017453292519943295769236907684886;
//a clockwise rotation, that would be counter clockwise; however,
the y axis is flipped.
return new
Point((oX+(Math.cos(radian)*hyp)),(oY+(Math.sin(radian)*hyp)));
}
//a good way of testing it would be to draw a line from each point
this.graphics.moveTo(225+120,200);
this.graphics.lineStyle(1,0x000000);
var p:Point;
for (var i =0; i<=360/* I wanted it to complete the shape other wise I
would have put i<360*/; i+=45/*set this as 45 in your case*/) {
p=pointOnCircle(i,120,225,200);
this.graphics.lineTo(Math.round(p.x),Math.round(p.y));
trace("At " + i +" degrees x="+Math.round(p.x)+", y="+Math.round(p.y));
}
p=null;
Merrill, Jason wrote:
x = Math.cos(angle) * radius
y = Math.sin(angle) * radius
With Flash player 9 and 10 and AS3, you actually don't need that use of
trigonometry anymore for this kind of thing with the introduction of
Point.polar(). Always good to still know the trig though, but for this,
you don't need to. Also, check out the new Point object in AS3 - no need
to keep track of X and Y separately - it's a convenience for handling
points as a single object.
Point.polar() does use radians instead of degrees, so here is a hand
method I wrote that takes degrees as input:
function polarToCartesian(distance:Number, degrees:Number):Point
{
var radians:Number = (degrees * Math.PI)/180;
return Point.polar(distance, radians);
}
So let's say you have two movie clips or sprites on the stage. You can
position one object relative to the other this way using this function:
var newPoint:Point = polarToCartesian(150, 65);
clip2.x = clip1.x + newPoint.x;
clip2.y = clip1.y + newPoint.y;
There are some other methods that are handy too. Here is my
MathTranslation class I wrote that has a lot of handy stuff like this in
it:
package com.boa.utilities
{
import flash.geom.Point;
/**
* @author Jason Merrill - Bank of America
*/
public class MathTranslation
{
public static function
degreesToRadians(degrees:Number):Number
{
return (degrees * Math.PI)/180;
}
public static function
radiansToDegrees(radians:Number):Number
{
return (radians*180)/Math.PI;
}
public static function polarToCartesian(distance:Number,
degrees:Number):Point
{
var radians:Number = (degrees * Math.PI)/180;
return Point.polar(distance, radians);
}
public static function cartesianAngle(fromPoint:Point,
toPoint:Point):Number
{
var radians:Number =
Math.atan2(toPoint.y-fromPoint.y, toPoint.x-fromPoint.x);
var backAzimuthDegrees:Number =
MathTranslation.radiansToDegrees(radians);
return
MathTranslation.getBackAzimuth(backAzimuthDegrees);
}
public static function
getAngularDivisions(numDivisions:int, angleRange:int=360):Array
{
var divisions:Array = new Array();
var divider:int =
Math.floor(angleRange/numDivisions);
for(var i:int = 0; i<numDivisions; i++)
{
divisions.push(i*divider);
}
return divisions;
}
public static function
floatingPointToPercent(floatingPoint:Number):int
{
return Math.round(Number(floatingPoint)*100);
}
public static function
getBackAzimuth(angle:Number):Number
{
var backAzimuth:Number;
if(angle < 180)
{
var tempNeg:Number = angle-180;
backAzimuth = tempNeg + 360;
}
else
{
backAzimuth = angle-180;
}
return backAzimuth;
}
}
}
Jason Merrill
Bank of America Learning Performance Solutions Instructional
Technology & Media
Monthly meetings on the Adobe Flash platform for rich media experiences
- join the Bank of America Flash Platform Community
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders