aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-23 17:08:57 +0100
committerGitHub <noreply@github.com>2019-09-23 17:08:57 +0100
commit8d0a5c6e4835e8c0f4b1f0cf0fb2edbd73db3760 (patch)
tree508a96aec93ee272adba67993beec523e6096efb
parenta1b182e008f39e22a6fc9fd5884aa22ae2e99542 (diff)
parent6ed5abfaa1a26717410601a84d89a57d8c17738c (diff)
downloadperlweeklychallenge-club-8d0a5c6e4835e8c0f4b1f0cf0fb2edbd73db3760.tar.gz
perlweeklychallenge-club-8d0a5c6e4835e8c0f4b1f0cf0fb2edbd73db3760.tar.bz2
perlweeklychallenge-club-8d0a5c6e4835e8c0f4b1f0cf0fb2edbd73db3760.zip
Merge pull request #665 from Scimon/master
Intersection of 2 points
-rw-r--r--challenge-027/simon-proctor/perl6/ch-1.p629
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-027/simon-proctor/perl6/ch-1.p6 b/challenge-027/simon-proctor/perl6/ch-1.p6
new file mode 100644
index 0000000000..6f68aeee29
--- /dev/null
+++ b/challenge-027/simon-proctor/perl6/ch-1.p6
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Takes 8 points for the lines (a,b) -> (c,d) and (p,q) -> (r,s)
+#| Outputs the intersection
+sub MAIN( Rat() \a, Rat() \b, Rat() \c, Rat() \d,
+ Rat() \p, Rat() \q, Rat() \r, Rat() \s ) {
+
+ my \a1 = d - b;
+ my \b1 = a - c;
+ my \c1 = a1*(a) + b1*(b);
+
+ my \a2 = s - q;
+ my \b2 = p - r;
+ my \c2 = a2*(p)+ b2*(q);
+
+ my \determinant = a1*b2 - a2*b1;
+
+ say "Lines ({a},{b}) -> ({c},{d}) and ({p},{q}) -> ({r},{s})";
+
+ if ( determinant == 0 ) {
+ say "Lines are parallel. No intersection";
+ } else {
+ my \x = (b2*c1 - b1*c2)/determinant;
+ my \y = (a1*c2 - a2*c1)/determinant;
+ say "Intersection at ({x},{y})";
+ }
+}