perlquestion
Pizentios
Hi monks!<br>
<br>
<p>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.</p>
<p>Bit of backstory:<br>
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.</p><br>
<p>Here's the code i've used:</p>
<code>
use strict;
use warnings;
use Math::Trig qw(great_circle_distance deg2rad pi rad2deg great_circle_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";
</code>
<p>This ofcourse returns angles to the lines from 0 degrees (strait north)</p>
<p> 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).</p><br>I am however at a loss on how to proceed further....<br>
<p>
I have constants on a x,y grid that are as follows:<br>
Point A: x=1019,y=1698<br>
Point B: x=79,y=1138<br>
Distance between Point A and Point B is: 1094<br>
</p>
<p>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).</p>
<br>
Circle at Point A's radius: 781.5815<br>
Circle at Point B's radius: 431.2683009<br>
<br>
<p>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. </p>
<p>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.</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-996246">
-Pizentios
</div></div>