Pizentios has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl and Solving Trig/Converting GPS to x,y Cords
by davido (Cardinal) on Jan 09, 2013 at 07:50 UTC | |
Re: Perl and Solving Trig/Converting GPS to x,y Cords
by BrowserUk (Patriarch) on Jan 08, 2013 at 22:11 UTC | |
Re: Perl and Solving Trig/Converting GPS to x,y Cords
by roboticus (Chancellor) on Jan 08, 2013 at 20:39 UTC | |
by BrowserUk (Patriarch) on Jan 08, 2013 at 22:09 UTC | |
by roboticus (Chancellor) on Jan 09, 2013 at 13:43 UTC | |
by BrowserUk (Patriarch) on Jan 09, 2013 at 13:57 UTC | |
by roboticus (Chancellor) on Jan 09, 2013 at 14:06 UTC | |
| |
Re: Perl and Solving Trig/Converting GPS to x,y Cords
by Pizentios (Scribe) on Jan 09, 2013 at 14:33 UTC |