About Line2D Object:functions

Line2D has so many functions to do. It has to update all of its relative values itself with change in each of its properties through set/get functions. In addition to these, it has to return dot product, cross product between two lines. More importantly, It has to tell us whether a line is intersecting with other line, and if they were intersecting, it has to return the Intersection details for us.

Above sample shows some important static functions of the Line2D Object. They are static functions,because I want to relate all the Lines and points on the stage as we can find the orientation details of them in a mutual understanding. I want to maintain a Relational Integrity (which is the  concept in building database tables) for all those points and lines on the Stage. As in the first example, if you want to know the details of one line, it's p0,p1,vx,vy,p1, length and Angle are enough. When You want to know about relationships between two lines or a line and a point, the complexity will be higher. If you are comparing two lines, mathematically calculating dot product and   cross product. And for Visual Orientation, you want to know whether they are parellel or not. If they are not parellel, we need to get at which Point they will intersect. I am not going too much on dot product and cross product as I  know too little about them. I just Implimented an applicable equation from an online mathematics tutorial. And, I am very much concerned about the Intersection,Bounce and Touch features of the Line, because they are very important for Flash Animation Creators. There, I went deep  delving into these features very clearly.

Generally all the People, who worked on Intersection on web sites (even that math gurus) took it as only a point. But It is not. There is an angle, a point and a ratio - were attached as features for the IntersectionPhenomena. Yes, Intersection is a pheomena and its features are IntersectionAngle: at which angle the two lines are intersecting, a relative angle of projection line with orientation line,IntersectionPoint: at which point the ProjectionLine is Intersecting on OrientationLine, and finally IntersectionRatio: which tells us the status report of the Intersection. If the ratio is greater than 1,the lines are not intersecting now but will intersect in future If we extend one of the line in positive direction furher enough to cover that point. If the ratio is between 0 and 1 the lines are currently intersecting on their segment range. If the ratio is negative value, that is lower than Zero, the lines are in after Intersection completed state, that means, If you extend the one of the lines backward, you can see the intersection on the segment range - that's the total concept behind a simple Intersection!

Now, I will explain you the Second Demo. In the First Box on Top Left Corner, I simply showed two intesectiong lines and their Important data. As they are not parellel,they are intersecting, right! I have explained you about the Intersection already. The second box is again has an Important thing to explain. As I said above, If you want to know about two lines, You are seeing their cross point as an intersection. What if you want to know the relation between a line and a point? The relation is to know where the point will touch the Line segment if we moved the point towards the line in a perpendicular angle.That is the TouchPoint This Touch Phenomena also has three features just like Intersection. But their description differs.TouchAngle is the relative angle between the external Point and the StartPoint(p0) of the Line. TouchPoint is the internal point where the Point touches the LineSegment.TouchRatio is just like that of Intersectration Ratio.You can also know that whether it is on the projection line, if the TouchAngle is zero means, The Point is positioned on the Line Projection. In that case the coordinates of external point and internal point are also same, Right!

The code for the First example(Top Left box) will be Like this:

var pntPoint1:Point=new Point(70,140);
var pntPoint2:Point=new Point(72,40);
var line1Args:Array=new Array(pntPoint1,pntPoint2);
var my_Line1:Line2D=new Line2D(line1Args);my_Line1.render(graphics,true,0x000000);

var pntPoint3:Point=new Point(50,140);
var pntPoint4:Point=new Point(90,40);
var line2Args:Array=new Array(pntPoint3,pntPoint4);
var my_Line2:Line2D=new Line2D(line2Args);

And for the Display Message I used the functions like Line2D.dotProductN(my_Line1,my_Line2) , Line2D.crossProductN(my_Line1,my_Line2) and Line2D.isParellels(my_Line1,my_Line2).

Code for the Second Box which shows Touch Point :

var pntPoint5:Point=new Point(50,240);
var pntPoint6:Point=new Point(90,160);

var line3Args:Array=new Array(pntPoint5,pntPoint6);
var my_Line3:Line2D=new Line2D(line3Args);
//line defined
//line rendered
var pntPoint7:Point=new Point(stage.stageWidth/2-100,stage.stageHeight/2+70);
var my_Touch_Point:Point=new Point(Line2D.getTouch(my_Line3,pntPoint7).p.x,Line2D.getTouch(my_Line3,pntPoint7).p.y);
//Point defined with red circle
//Touch point depicted with blue circle
p class="mdl">The Left down Most Box shows the BouncePhenomena. This is the most complicated thing, of all the features of the Line2D object. Please pay attention to understand the concept. I am somewhere feeling that I may confuse you if I explained too much. In the next example, there is a dynamic live Example to undestand its application in real world. For now I took a static show. Here the red color Projection Line is Intersecting the black color Orientation Line and Bouncing as green color Reflection Line. Yes, it is equally comparable to a ray reflecting on a surface into its old medium. To understand the actual phenomena we have to split the projection in two parts.First part is from its StartPoint to IntersectionPoint, and the second part is from the IntersectionPoint to its ClosePoint. The Bouncing Line is not how much it is touching the orientation, but how much it crossed the orientation, Am I Right? The angles are normally following the reflection dynamics;that is the incidence angle and reflecting angle are equal. I think that much explanation is enough about what you are seeing there.

The right side top most box shows another static function of line2D that is getResultantLine. This is simple adding lines. The concept is simply adding the vectors. By this function we can add as many lines as we can and it wll return the final Line2D object. And in the simplistic vector additions it is the value is important. But I have extended it in the return value.The code will be like below:

var pntPoint12:Point=new Point(460,50);
var pntPoint13:Point=new Point(550,150);
//first Line Points
var line7Args:Array=new Array(pntPoint12,pntPoint13);
var my_Line7:Line2D=new Line2D(line7Args);
//created first blue line
var int_new_Close_X:Number=my_Line7.p0.x+(my_Line7.Length*Math.cos((my_Line7.Rotation+30)*(Math.PI/180)));
var int_new_Close_Y:Number=my_Line7.p0.y+(my_Line7.Length*Math.sin((my_Line7.Rotation+30)*(Math.PI/180)));
var my_new_POint:Point=new Point(int_new_Close_X,int_new_Close_Y);
//shifted the p1 of first line 30 degres more
var line8Args:Array=new Array(pntPoint12,my_new_POint);
var my_Line8:Line2D=new Line2D(line8Args);
//created green line
var my_cross_point:Point=new Point(Line2D.getIsect(my_Line7,my_Line8).p.x,Line2D.getIsect(my_Line7,my_Line8).p.y);
//found the Intersection and depicted it
var arr_Lines:Array=new Array(my_Line7,my_Line8);
var obj_Added_Line:Line2D=Line2D.getResultantLine(arr_Lines,my_cross_point);
//projecting the added line from the Intersection Point

My concern as a Programmer is where to start this Added Line. So, I gave another argument start point. Here in this example I am reminding about force lines. When two forces are acting upon an object from different angles, In which dirction the object will move and where it will settles at last? This is the visual answer for that question! Before I am moving to the next sample. There is some thing to say about two public functions of Line2D.they are moveTo and moveBy. In the first basic demo, you tossed with p0 and p1 values.Here with moveTo. I am doing the same thing,but I gave the control to the User Programmer as a public function.