Guest User

Untitled

a guest
Apr 14th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. In my spark layout updateDisplayList method (not complete, just the relevant stuff):
  2.  
  3. var totalAngleSoFar:Number = 0;
  4.             totalAngleSoFar -= Math.PI / 4;
  5.            
  6.             iter.reset();
  7.             while (element = iter.nextElement())
  8.             {
  9.                 polarElement = IPolarElement(element); 
  10.                 var position:Point = RadialUtil.convertPolarToCartesian(new Point(polarElement.radius + layoutTarget.itemOffset, totalAngleSoFar), polarElement.origin);
  11.                 var targetRotation:Number = RadialUtil.convertRadiansToDegrees(totalAngleSoFar);
  12.                
  13.  
  14. // If I comment this out, all is well but everything is rendered straight. The x, y seem to be correct, though:
  15.                                 polarElement.rotation = targetRotation;
  16.  
  17.  
  18.                 element.setLayoutBoundsPosition(position.x, position.y);
  19.                
  20.                
  21.                
  22.                 // Move on to next item
  23.                 totalAngleSoFar += polarElement.theta;
  24.             }
  25.  
  26. RadialUtil:
  27.  
  28. package net.skai.utils
  29. {
  30.     import flash.geom.Point;
  31.  
  32.     public class RadialUtil
  33.     {
  34.        
  35.         // in Polar points, x == radius and y == theta.
  36.        
  37.         public static function convertCartesianToPolar(input:Point):Point {
  38.             var theta:Number;
  39.            
  40.             if (input.x > 0) {
  41.                 theta = Math.atan(input.y / input.x);
  42.             } else if (input.x < 0 && input.y >= 0) {
  43.                 theta = Math.atan(input.y / input.x) + Math.PI;
  44.             } else if (input.x < 0 && input.y < 0) {
  45.                 theta = Math.atan(input.y / input.x) - Math.PI;
  46.             } else if (input.x == 0 && input.y > 0) {
  47.                 theta = Math.PI / 2;
  48.             } else if (input.x == 0 && input.y < 0) {
  49.                 theta = Math.PI / -2;
  50.             } else if (input.x == 0 && input.y == 0) {
  51.                 theta = 0;
  52.             }
  53.            
  54.             return new Point(Math.sqrt(input.x ^ 2 + input.y ^ 2), theta);
  55.         }
  56.        
  57.         public static function convertPolarToCartesian(input:Point, origin:Point = null):Point {
  58.            
  59.             var retVal:Point = new Point((input.x * Math.cos(input.y)), (input.x * Math.sin(input.y)));
  60.            
  61.             if (origin) {
  62.                 retVal.x += origin.x;
  63.                 retVal.y += origin.y;
  64.             }
  65.            
  66.            
  67.             return retVal;
  68.         }
  69.        
  70.         public static function convertDegreesToRadians(input:Number):Number {
  71.             return (input * Math.PI) / 180;
  72.         }
  73.        
  74.         public static function convertRadiansToDegrees(input:Number):Number {
  75.             return (input * 180) / Math.PI;
  76.         }
  77.     }
  78. }
Add Comment
Please, Sign In to add comment