Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Perl and Solving Trig/Converting GPS to x,y Cords by Pizentios

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2018-02-20 04:22 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (267 votes). Check out past polls.