Hi monks!
I have a problem that i know can be solved by using trig. However i am at a loss on how to go about it in perl.
Bit of backstory:
At work we have a map that uses x,y cords to place objects on it. However we need to "convert" gps lat and long cords to fit on this map. I have two reference points on the map already that will be constant for every caculation. Using Math::Trig i have figured out the angles (read bearings) of the two reference points as well as the bearings from the reference points to my test point using the gps lat and long values.
Here's the code i've used:
use strict;
use warnings;
use Math::Trig qw(great_circle_distance deg2rad pi rad2deg great_circl
+e_direction);
my $low_right_lat ="49.033312";
my $low_right_long ="95.261125";
my $upper_left_lat ="51.361154";
my $upper_left_long ="101.353263";
my $user_lat ="49.752852";
my $user_long ="100.119849";
sub NESW { deg2rad($_[0]), deg2rad(90$_[1]) }
my @A = NESW($low_right_long, $low_right_lat);
my @B = NESW($upper_left_long, $upper_left_lat);
my @USER = NESW($user_long, $user_lat);
my $angle_a_to_user = great_circle_direction(@A, @USER); #in rads.
my $angle_a_to_user_deg = rad2deg($angle_a_to_user);
my $angle_b_to_user = great_circle_direction(@B, @USER); #in rads.
my $angle_b_to_user_deg = rad2deg($angle_b_to_user);
my $angle_a_to_b = great_circle_direction(@A, @B); #in rads.
my $angle_a_to_b_deg = rad2deg($angle_a_to_b);
my $angle_b_to_a = great_circle_direction(@B, @A); #in rads.
my $angle_b_to_a_deg = rad2deg($angle_b_to_a);
print "Angle From A to User is: $angle_a_to_user_deg\n";
print "Angle From B to User is: $angle_b_to_user_deg\n";
print "Angle From A to B is: $angle_a_to_b_deg\n";
print "Angle From B to A is: $angle_b_to_a_deg\n";
This ofcourse returns angles to the lines from 0 degrees (strait north)
Using this information i am able to use the law of sines and the law of cosines (and some addition/subtraction to get the angle from line AB to line AC and line BC) to figure out the length of the sides that are made to my test point on the x,y graph (on paper but it should translate to perl code fairly easy).
I am however at a loss on how to proceed further....
I have constants on a x,y grid that are as follows:
Point A: x=1019,y=1698
Point B: x=79,y=1138
Distance between Point A and Point B is: 1094
I am trying to caculate the x,y cords for a point that i would like to map. My thoughts are to find the intersection of two circles, as i know the radius of each circle (from my math on paper, one centered on Point A and the other centered on Point B).
Circle at Point A's radius: 781.5815
Circle at Point B's radius: 431.2683009
Can somebody please give me some tips or suggestions on how to proceed to solve this problem in perl? Code examples would be greatly appreciated....This is the first time i've had to do any kind of higher level math in perl.
It doesn't have to be solved using intersection of two circles if sombody out there has a better method of figuring it out...and i must admit my trig skills are very rusty as i haven't used em much since high school.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
 a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)

For: 

Use: 
 &   & 
 <   < 
 >   > 
 [   [ 
 ]   ] 
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.