Geo::Sun::Bearing - Calculates the bearing from a station on the surface of the Earth to the Sun.


Geo-Sun documentation Contained in the Geo-Sun distribution.

Index


Code Index:

NAME

Top

Geo::Sun::Bearing - Calculates the bearing from a station on the surface of the Earth to the Sun.

SYNOPSIS

Top

  use Geo::Sun::Bearing;
  use GPS::Point;
  my $datetime=DateTime->now;
  my $station=GPS::Point->new(lat=>39, lon=>-77);
  my $gs=Geo::Sun::Bearing->new->set_datetime($datetime)->set_station($station);
  printf "Bearing from Station to Sun is %s\n", $gs->bearing;

DESCRIPTION

Top

The Geo::Sun::Bearing is a Geo::Sun object. This package calculates the bearing from a station on the surface of the Earth to the point where the Sun is directly over at the given time.

USAGE

Top

  use Geo::Sun::Bearing;
  my $gs=Geo::Sun::Bearing->new;

CONSTRUCTOR

Top

new

  my $gs=Geo::Sun::Bearing->new; #Inherited from Geo::Sun
  my $gs=Geo::Sun::Bearing->new(datetime=>$dt, station=>$station);

METHODS

Top

Many methods are inherited from Geo::Sun.

bearing

Returns the bearing from the station to the Sun.

bearing_dt_pt

Returns bearing given a datetime and a station point.

  my $bearing=$gs->bearing_dt_pt($datetime, $station);

Implemented as

  my $bearing=$gs->set_datetime($datetime)->set_station($station)->bearing;

station

Sets or returns station. Station must be a valid point argument for GSP::Point distance method. Currently, Geo::Point and GPS::Point. I'm planning to add {lat=>$lat, lon=>$lon} and [$lat, $lon] shortly.

set_station

Sets station returns self

METHODS (INTERNAL)

Top

point_onchange

Overridden from Geo::Sun to recalculate the bearing when the point changes

bearing_recalculate

Method which is called to recalculate the bearing when the datetime or the station is changed.

bearing_onchange

In this base module this does nothing but to return the object

Override this function if you want to calculate something when the bearing changes. By nature this hook also gets called when point_onchange is called so don't override both.

BUGS

Top

Please send to the geo-perl email list.

SUPPORT

Top

Try the geo-perl email list.

LIMITATIONS

Top

Calculations are only good to about 3 decimal places.

AUTHOR

Top

    Michael R. Davis
    CPAN ID: MRDVT
    STOP, LLC
    domain=>stopllc,tld=>com,account=>mdavis
    http://www.stopllc.com/

COPYRIGHT

Top

SEE ALSO

Top


Geo-Sun documentation Contained in the Geo-Sun distribution.
package Geo::Sun::Bearing;
use strict;
use warnings;
use Geo::Inverse 0.05; #GPS::Point->distance need array context
use base qw{Geo::Sun};

BEGIN {
    use vars qw($VERSION);
    $VERSION     = '0.04';
}

sub initialize2 {
  my $self=shift;
  $self->bearing_recalculate if defined $self->station;
  $self->initialize3; #a hook if you need it
  return $self;
}

sub initialize3 {
  my $self=shift;
  return $self;
}

 
sub bearing {
  my $self=shift;
  return $self->{'bearing'};
}

sub bearing_dt_pt {
  my $self=shift;
  my $datetime=shift;
  my $station=shift;
  return $self->set_datetime($datetime)->set_station($station)->bearing;
}

sub station {
  my $self=shift;
  if (@_) {
    $self->{"station"}=shift;
    $self->bearing_recalculate;
  }
  return $self->{"station"};
}

sub set_station {
  my $self=shift;
  $self->station(@_) if @_;
  return $self;
}

sub point_onchange {
  my $self=shift;
  $self->bearing_recalculate if defined $self->station;
  return $self;
}

sub bearing_recalculate {
  my $self=shift;
  my (undef, $baz, undef) = $self->point->distance($self->station);
  $self->{'bearing'}=$baz;
  $self->bearing_onchange; #a hook if you need it
  return $self;
}

sub bearing_onchange {
  my $self=shift;
  return $self;
} 

1;