---
title: "Flex中使用三角函数sin() cos()进行圆形排列"
author: "cloud21"
date: "2011-05-14T13:16:25Z"
tags: []
categories: ["Web前端"]
slug: "flex-sin-cos"
draft: false
lastmod: "2011-05-14T13:16:25Z"
id: 1044146
url: "https://cloud21.iteye.com/blog/1044146"
---

private const CENTRE:Point = new Point(0, 0); //圆心

private const RADIUS:Number = 100; //半径

private const START_ANGLE:Number = 15; //起初角度

private const Tile_TOTAL:Number = 9; //组件个数

private const SINGLE_ANGLE:Number = 360 / Tile_TOTAL; //平均角度

 

for(var i:uint=0; i<Tile_TOTAL; i++){

	var pb:Tile = new Tile(); //新建组件

	var angle:uint = i * SINGLE_ANGLE + START_ANGLE; //角度

	var p:Point = getPoint(angle);

	pb.x = p.x; pb.y = p.y; //移动组件

	pb.rotation = angle - 90; //旋转组件

	this.addElement(pb); //加到舞台

}

 

private function getPoint(angle:uint):Point{

	var angleRadians:Number = angle * Math.PI / 180; //换算成弧度

	var p:Point = new Point(Math.cos(angleRadians) * RADIUS, Math.sin(angleRadians) * RADIUS); //计算偏移量

	p.x += CENTRE.x; //跟据圆心对偏移量进行修正

	p.y += CENTRE.y; //跟据圆心对偏移量进行修正

	return p;

}