in reply to Re: calculating planet conjunction with mojo front end
in thread calculating planet conjunction with mojo front end

There must be some equations governing these phenomena and perhaps you can solve them to get the answer analytically rather than with iterating?

Astro::Coords - Class for handling astronomical coordinates

#!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coords; print qq/Planet\tRight Ascension\t\tDeclination\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); my $ra = $planet->ra(format => q/deg/); my $dec = $planet->dec(format => q/deg/); print qq/$name\t$ra\t$dec\n/ }
Output:
Planet	Right Ascension		Declination
Jupiter	300.231916167496	-21.0148733591416
Saturn	301.371438440471	-20.6884105467964
One-liner:
perl -MAstro::Coords -MTime::Piece -Mstrict -e 'print qq/Planet\tRight + Ascension\t\tDeclination\n/; for my $name (qw/Jupiter Saturn/) { my +$planet = Astro::Coords->new(planet => $name); $planet->datetime(Time +::Piece->new); my $ra = $planet->ra(format => q/deg/); my $dec = $pla +net->dec(format => q/deg/); print qq/$name\t$ra\t$dec\n/}'

Replies are listed 'Best First'.
Re^3: calculating planet conjunction with mojo front end
by Anonymous Monk on Dec 11, 2020 at 17:25 UTC
    Use Astro::Telescope to calculate the position in the sky from your location:
    #!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coords; use Astro::Telescope; print qq/Planet\tAzimuth\t\t\tElevation\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); $planet->telescope(Astro::Telescope->new( Name => q/1600 Pennsylvania Ave, Washington DC/, Long => -77, Lat => 38.9, Alt => 16.7)); my $az = $planet->az(format => 'deg'); my $el = $planet->el(format => 'deg'); print qq/$name\t$az\t $el\n/ }
    Output:
    Planet	Azimuth			Elevation
    Jupiter	132.670727106298	 -7.05306603251409
    Saturn	131.551952092501	 -7.04332546770451
    
      Oops forgot that Astro::Telescope requires Lat and Long in radians:
      #!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coord::ECI::Utils 'deg2rad'; use Astro::Coords; use Astro::Telescope; print qq/Planet\tAzimuth\t\t\tElevation\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); $planet->telescope(Astro::Telescope->new( Name => '1600 Pennsylvania Ave, Washington DC', Long => deg2rad(-77), Lat => deg2rad(38.9), Alt => 16.7)); my $az = $planet->az(format => 'deg'); my $el = $planet->el(format => 'deg'); print qq/$name\t$az\t $el\n/ }
Re^3: calculating planet conjunction with mojo front end
by Anonymous Monk on Dec 11, 2020 at 16:54 UTC
    For sexagesimal notation omit the format parameter:
    #!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coords; print qq/Planet\tRight Ascension\t\tDeclination\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); my $ra = $planet->ra; my $dec = $planet->dec; print qq/$name\t$ra\t$dec\n/ }
    Output:
    Planet	Right Ascension		Declination
    Jupiter	20:00:56.326	-21:00:51.63
    Saturn	20:05:29.464	-20:41:17.35
    
Re^3: calculating planet conjunction with mojo front end
by Aldebaran (Curate) on Dec 12, 2020 at 07:52 UTC

    Very nice. Notice that we got different results. When I took Stellar Evolution, we were doing well to get within an order of magnitude with many first order approximations./p>

    $ ./1.astro.pl Planet Right Ascension Declination Jupiter 300.371015239225 -20.9886573993409 Saturn 301.438145819967 -20.6756490862067 $ cat 1.astro.pl #!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coords; print qq/Planet\tRight Ascension\t\tDeclination\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); my $ra = $planet->ra(format => q/deg/); my $dec = $planet->dec(format => q/deg/); print qq/$name\t$ra\t$dec\n/ } sleep 2; __END__ $

    We'll see where this folds into the ultimate product. Thanks for yor comments.

      Notice that we got different results. When I took Stellar Evolution...

      Unlike the minuscule proper motion of stars, the planets constantly move relatively rapidly across the sky, so the coordinates will be different each time they are calculated.

      #!/usr/bin/perl use strict; use warnings; use Time::Piece; use Astro::Coords; while () { system 'clear'; print qq/Planet\tRight Ascension\t\tDeclination\n/; for my $name (qw/Jupiter Saturn/) { my $planet = Astro::Coords->new(planet => $name); $planet->datetime(Time::Piece->new); my $ra = sprintf('%.12f', $planet->ra(format => 'deg')); my $dec = sprintf('%.12f', $planet->dec(format => 'deg')); print qq/$name\t$ra\t$dec\n/; } sleep 1 }

        !!