AS3 to find the intersection of two straight lines

Source: Internet
Author: User

Paste to the frame to run

var p1start:point = new Point (0,0), var p1end:point = new Point (50,50), var p2start:point = new Point (50,50), Var p2end:point = new Point (100,100), var p:point = new Point (), Trace (CheckPoint ()) function CheckPoint () {if (p1start.x = = p1end.x) {if (p2s Tart.x = = p2end.x) {Trace ("parallel");p = null;} else{p.x = P1START.X;P.Y = p2start.y+ (p1start.x-p2start.x)/(p2end.x-p2start.x) * (P2END.Y-P2START.Y);}} else if (p2start.x = = p2end.x) {p.x = P2start.x;p.y = p1start.y+ (p2start.x-p1start.x)/(p1end.x-p1start.x) * ( P1END.Y-P1START.Y);} Else{var K1:number = (p1start.y-p1end.y)/(p1start.x-p1end.x); var k2:number = (p2start.y-p2end.y)/(p2Start.x-p2End.x) if (K1 = = K2) {Trace ("parallel");p = null;} Else{var B1:number = (p1start.x*p1end.y-p1start.y*p1end.x)/(p1start.x-p1end.x); var b2:number = (p2Start.x* p2end.y-p2start.y*p2end.x)/(p2start.x-p2end.x);p. x = (B2-B1)/(K1-K2);p. y = K1 * p.x + B1;}} return p;}

  

AS3 to find the intersection of two straight lines

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.