Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: line segment intersection

by Anonymous Monk
on Jun 30, 2015 at 17:27 UTC ( [id://1132652]=note: print w/replies, xml ) Need Help??


in reply to line segment intersection

sub intersectLines { #working subroutine. thanks to the original poster. my( $ax, $ay, $bx, $by, $cx, $cy, $dx, $dy )= @_; my @rval=0; my $d1=($ax-$bx)*($cy-$dy); my $d2=($ay-$by)*($cx-$dx); my $dp = $d1 - $d2; my $dq = $d2 - $d1; if($dp!=0 && $dq!=0) { my $p = ( ($by-$dy)*($cx-$dx) - ($bx-$dx)*($cy-$dy) ) / $dp; + my $q = ( ($dy-$by)*($ax-$bx) - ($dx-$bx)*($ay-$by) ) / $dq; if($p>0 && $p<=1 && $q>0 && $q<=1) { my $px= $p*$ax + (1-$p)*$bx; my $py= $p*$ay + (1-$p)*$by; @rval=($px, $py); } } return(@rval); }

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1132652]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-25 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found