perlynewby has asked for the wisdom of the Perl Monks concerning the following question:
I was playing with some puzzles and I wanted to create a program in perl that given a set of data , it can figure out if it is a rectangle or not.
the fun part is that I am given 3 points, how do I prove a 4th point will make a rectangle?
I tested for parallel sides to be congruent and have a single 90 angle to prove it
my question is there a module in perl that can take a set of points to figure out lengths, angles...too messy with all little calculations to get lengths
I , as always, looking for some advice in making my program more readable and extending my perl experience with modules
# C(cx,cy)* ****** *D(?x,?y) # * * # * * # A(ax,ay)* ****** * B(bx,by) use strict; use warnings; use Data::Dump qw(dump); use Math::Trig; my @points = ( 1,5, #point A 5,5, #point B 1,9, #point C ); my @new =( 5,9); #point D will be given by user later (testing my +theory) #lets' get the length of each segment; if parallel sides are equal #plus #test for 90 angles and IT's a rectangle or square # GET LENGTHS : #from A to B my $ABx= $points[2]-$points[0]; my $ABy= $points[3]-$points[1]; #points from A to C my $ACx= $points[4]-$points[0]; my $ACy= $points[5]-$points[1]; #get length to new points from C TO D my $CDx= $new[0]-$points[4]; my $CDy= $new[1]-$points[5]; #from B to D my $BDx= $new[0]-$points[2]; my $BDy= $new[1]-$points[3]; #test if lengths are the same #if so, then test if all angles are 90 if ($ABx == $CDx && $ACy == $BDy){ #find angle my $a= atan($ABx/$ACy)*(360/pi); $a==90 ? print "this is a Rectangle/square\n" : print "this is a r +hombus of some sort\n"; }else { print " This shape doesn't have congruent sides; NOT a RECTANG +LE or Square";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there a Module that can handle a set of data points?
by NetWallah (Canon) on Nov 12, 2015 at 06:41 UTC | |
|
Re: Is there a Module that can handle a set of data points?
by salva (Canon) on Nov 12, 2015 at 08:22 UTC | |
|
Re: Is there a Module that can handle a set of data points?
by LanX (Saint) on Nov 12, 2015 at 07:48 UTC | |
by perlynewby (Scribe) on Nov 13, 2015 at 11:42 UTC | |
by perlynewby (Scribe) on Nov 13, 2015 at 11:49 UTC | |
by hippo (Archbishop) on Nov 13, 2015 at 12:10 UTC |