Packageutils.geom
Classpublic class VectorRenderer
InheritanceVectorRenderer Inheritance Object

A helper class used for visualizing vectors.

View the examples



Public Properties
 PropertyDefined By
  graphics : Graphics
The graphics object used for the drawings.
VectorRenderer
Public Methods
 MethodDefined By
  
VectorRenderer(graphics:Graphics)
Constructor.
VectorRenderer
  
clear():void
Clears the graphics object.
VectorRenderer
  
renderArrow(v:Point, color:uint = 0x000000, scale:Number = 1.0, drawArrowHead:Boolean = true):void
Draws an arrow representing the vector.
VectorRenderer
  
renderTriangle(v:Point, color:uint = 0, scale:Number = 1.0):void
Draws a triangle using the vector as the hypotenuse.
VectorRenderer
Property Detail
graphicsproperty
public var graphics:Graphics

The graphics object used for the drawings.

Constructor Detail
VectorRenderer()Constructor
public function VectorRenderer(graphics:Graphics)

Constructor.

Parameters
graphics:Graphics — The graphics object used for the drawings.
Method Detail
clear()method
public function clear():void

Clears the graphics object.

renderArrow()method 
public function renderArrow(v:Point, color:uint = 0x000000, scale:Number = 1.0, drawArrowHead:Boolean = true):void

Draws an arrow representing the vector.

Parameters

v:Point — The vector or point to use as the hypotenuse.
 
color:uint (default = 0x000000) — The color of the lines of the triangle. Default is black.
 
scale:Number (default = 1.0) — The amount to scale up the size of the triangle. Default is 1.0 (no change)
 
drawArrowHead:Boolean (default = true) — When true, draws the arrowhead. When false, only a line is drawn.

renderTriangle()method 
public function renderTriangle(v:Point, color:uint = 0, scale:Number = 1.0):void

Draws a triangle using the vector as the hypotenuse.

Parameters

v:Point — The vector or point to use as the hypotenuse.
 
color:uint (default = 0) — The color of the lines of the triangle. Default is black.
 
scale:Number (default = 1.0) — The amount to scale up the size of the triangle. Default is 1.0 (no change)

Examples
Draw an arrow representing a velocity vector.
         package {
            import flash.display.Shape;
            import flash.display.Sprite;
            import flash.events.Event;
            import flash.geom.Point;
            import flash.utils.getTimer;
            
            import utils.geom.VectorRenderer;
            
            [SWF(frameRate="60")]
            public class TestRender extends Sprite
            {
                public function TestRender()
                {
                    super();
                    
                    var shape:Shape = new Shape(); 
                    shape.y = 300;
                    addChild(shape);
                    
                    var vel:Point = new Point(2,-5); 
                    var accel:Point = new Point(0, 0.05);
                    
                    var renderer:VectorRenderer = new VectorRenderer(shape.graphics);
                    
                    addEventListener(Event.ENTER_FRAME, function onEnterFrame(event:Event):void {
                        vel = vel.add(accel);
                        shape.x += vel.x;
                        shape.y += vel.y;
                        
                        renderer.clear();
                        renderer.renderArrow (vel, 0xFF00FF, 8.0, true);
                    });
                }
            }
        }