Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In my spark layout updateDisplayList method (not complete, just the relevant stuff):
- var totalAngleSoFar:Number = 0;
- totalAngleSoFar -= Math.PI / 4;
- iter.reset();
- while (element = iter.nextElement())
- {
- polarElement = IPolarElement(element);
- var position:Point = RadialUtil.convertPolarToCartesian(new Point(polarElement.radius + layoutTarget.itemOffset, totalAngleSoFar), polarElement.origin);
- var targetRotation:Number = RadialUtil.convertRadiansToDegrees(totalAngleSoFar);
- // If I comment this out, all is well but everything is rendered straight. The x, y seem to be correct, though:
- polarElement.rotation = targetRotation;
- element.setLayoutBoundsPosition(position.x, position.y);
- // Move on to next item
- totalAngleSoFar += polarElement.theta;
- }
- RadialUtil:
- package net.skai.utils
- {
- import flash.geom.Point;
- public class RadialUtil
- {
- // in Polar points, x == radius and y == theta.
- public static function convertCartesianToPolar(input:Point):Point {
- var theta:Number;
- if (input.x > 0) {
- theta = Math.atan(input.y / input.x);
- } else if (input.x < 0 && input.y >= 0) {
- theta = Math.atan(input.y / input.x) + Math.PI;
- } else if (input.x < 0 && input.y < 0) {
- theta = Math.atan(input.y / input.x) - Math.PI;
- } else if (input.x == 0 && input.y > 0) {
- theta = Math.PI / 2;
- } else if (input.x == 0 && input.y < 0) {
- theta = Math.PI / -2;
- } else if (input.x == 0 && input.y == 0) {
- theta = 0;
- }
- return new Point(Math.sqrt(input.x ^ 2 + input.y ^ 2), theta);
- }
- public static function convertPolarToCartesian(input:Point, origin:Point = null):Point {
- var retVal:Point = new Point((input.x * Math.cos(input.y)), (input.x * Math.sin(input.y)));
- if (origin) {
- retVal.x += origin.x;
- retVal.y += origin.y;
- }
- return retVal;
- }
- public static function convertDegreesToRadians(input:Number):Number {
- return (input * Math.PI) / 180;
- }
- public static function convertRadiansToDegrees(input:Number):Number {
- return (input * 180) / Math.PI;
- }
- }
- }
Add Comment
Please, Sign In to add comment