About Line2D Object:Introduction

Recently I have wrote a Line2D Class in AS3. It is a proud decendant of flash.geom.Point. Actually, I am intrigued by a thought:Why flash did not give us a Line next to Point and gave Rectangle directly? This curiosity haunted me from the begining: but  when I am doing a work which requires to know Intersection Point of a Line on another Line, then I felt a real pressure to know about it thoroughly. Basically I didn't have much knowledge in Math linear equations, But they are very Important to apply  in my work, what to do? So, I searched math reated internet sites vigorously and found that the related material is spread across the web randomly, without any integrity. Neccessity is the mother of all Inventions!  I took the responsibility to inegrate the knowledge what I acquired and I have assimilated all of that into a single Object.

Thus the Line2D object came into existance. In fact there are some static functions to the point class like distance and interpolate, and some public functions like equals, normalize, polar will serve to modify it in a way to create a Line to Push it up to the requirement. But it it is not sufficient for an advanced programming tasks. While I am doing online search, I found the functionalities of a line were more complicated. A line in mathematics has so many properties and functionalities unique to it, which are quite different to the Point. There is slope, which is very crucial for a line. And, we need to show normals on left and right. It's basic functionality  is to check and return Intersection Points with each one among all the lines we have created. And It also has to return touch points for any one of the created Points. Very importantly, It has to follow the mathematical y=mx+b equation with  precision. And  it has to bridge the gap between the mathematical calculations - which follow cartesian coordinate space - and the flash coordinate space. This is very important in scripted animation. Why because,  those who are using trigonometry in flash animations for angular displacement are now fallowing a tricky Y-Shift Logic- that is calculating all the basic things and applying a-ve value for y in the final step of calculations before applying angular motion for any of the displayobjects. I have observed that my Line2d Object is projecting itself by it's calculated values and rendering on Flash stage in a normal way without any abnormalities.

My line2D is purely a Mathematical Object and requires argument data in two ways:one is of two points, and the other is of  a start point,vx and vy. From this basic data, It will calculate all the relevant values like dx and dy, Length and Angle, Slope and Breadth (very Important in applying y=mx+b), And Normals Left and Right. All he Important Logic about a line entity is successfully clubbed into a single object Line2D class. After creating an instance of a line, we can alter its orientation through set/get public functions p0,p1,radAngle. In the below example, you may observe it is updating its Orientation beautifully.

Above sample shows basic rendering features. It's Instance Creation syntax would be like this;

var my_Point1:Point=new Point(70,140);
var my_Point2:Point=new Point(72,40);

var line1Args:Array=new Array(pntPoint1,pntPoint2);
var my_Line1:Line2D=new Line2D(line1Args);

As I explained you earlier, I am giving two different types of arguments,I could not define branching alternative arguments in its constructor, because Flash didn't provide constructor overiding like java classes. So, I took this way. Inside I am bifurcating the Argument Processing logic.You can define it in another way.

var line1Args:Array=new Array(pntPoint1,2,-100);
var my_Line1:Line2D=new Line2D(line1Args);

Both will be same. In general second method called as LineVector method, as it is using vx and vy. A vector has magnitude and direction. Here 2 will be the magnitude and -100 is direction. I took that notation in my Object. By default I am rendering Right Normal(Red Line) and Left Normal(Green Line) also. For all the basic dx/dy and Normal values, I followed mostly Mr.Tonypa's vector based animation tutorials for all these Linevector calculations. I am so thankfull to him for those valuble suggstions as response to my Inquisitive emails..

Through Slider change events I am doing these manipulations by code:

In first slider change event :

trace(sdr_slide_p0X.value);
my_Line1.p0=new Point(sdr_slide_p0X.value,my_Line1.p0.y);

Upto fourth slider The Syntax is same,except parameter change.But in Fifth Slider change, I changed the command like this:

trace(sdr_slide_Rot.value);
my_Line1.radAngle=sdr_slide_Rot.value*(Math.PI/180);

The last thing is just to convert the slider value, which is a whole number, into radians.Now, we are manpulating the changes by this argument value, just like we are applying a simple property value of that Line2D Object.