in reply to A little schoolboy math (but my schooldays were a long time ago).
sub solve{ my( $a, $b, $c, $d ) = @_; my( $x, $y ); $x = ($b - $a) / ($d - $a - $c + $b); $y = ($d - $a) * ($b - $a) / ($d - $a - $c + $b) + $a; return( $x, $y ); }
Ok, perhaps more efficiently...
sub solve{ my( $a, $b, $c, $d ) = @_; my $x = ($b - $a) / ($d - $a - $c + $b); my $y = ($d - $a) * $x + $a; return( $x, $y ); }
formula for line 1: Y = (D - A) * X + A formula for line 2: Y = (C - B) * X + B intersection: X and Y coordinates of line1 and line2 are equal ... (D - A) * X + A = (C - B) * X + B reduces to => X = (B - A) / (D - A - C + B) plug X into equation for line 1 gives ... Y = (D - A) * (B - A) / (D - A - C + B) + A
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: A little schoolboy math (but my schooldays were a long time ago).
by davido (Cardinal) on Feb 01, 2004 at 17:37 UTC |
In Section
Seekers of Perl Wisdom