An open API service indexing awesome lists of open source software.

https://github.com/dnmfarrell/math-shape-point

Perl class for a 2d point object in cartesian space with utility angle methods
https://github.com/dnmfarrell/math-shape-point

Last synced: over 1 year ago
JSON representation

Perl class for a 2d point object in cartesian space with utility angle methods

Awesome Lists containing this project

README

          

=pod

=encoding UTF-8

=head1 NAME

Math::Shape::Point - a 2d point object in cartesian space with utility angle methods

=head1 VERSION

version 1.05

=head1 SYNOPSIS

use Math::Shape::Point;
use Math::Trig ':pi';

my $p1 = Math::Shape::Point->new(0, 0, 0);
my $p2 = Math::Shape::Point->new(5, 5, 0);
$p1->rotate_about_point($p2, pip2);
my $angle = $p1->get_angle_to_point($p2);
my $distance = $p1->get_distance_to_point($p2);

=head1 DESCRIPTION

This module is designed to provide some useful 2d functions for manipulating point shapes in cartesian space. Advanced features include rotating around another point, calculating the distance to a point and the calculating the angle to another point. The module uses cartesian coordinates and radians throughout.

=for HTML
Coverage Status

=head1 METHODS

=head2 new

Instantiates a new point object. Requires the x and y cartesian coordinates and the facing direction in radians.

my $p = Math::Shape::Point->new(0, 0, 0);

=head2 get_location

Returns an arrayref containing the point's location in cartesian coordinates.

$p->get_location;

=head2 set_location

Sets the point's location in cartesian coordinates. Requires two numbers as inputs for the x and y location.

$p->set_location($x, $y);

=head2 get_direction

Returns the current facing direction in radians.

$p->get_direction;

=head2 set_direction

Sets the current facing direction in radians.

$p->set_direction(2.5);

=head2 advance

Requires a numeric distance argument - moves the point forward that distance in Cartesian coordinates towards the direction it is facing.

$p->advance(5);

=head2 retreat

Requires a numeric distance argument - moves the point backwards that distance in Cartesian coordinates from the direction it is facing.

$p->retreat(5);

=head2 move_left

Requires a numeric distance argument - moves the point that distance to the left.

$p->move_left(3);

=head2 move_right

Requires a numeric distance argument - moves the point that distance to the right.

$p->move_right(7);

=head2 rotate

Updates the point's facing direction by radians.

$p->rotate(2);

=head2 rotate_about_point

Rotates the point around another point of origin. Requires a point object and the angle in radians to rotate. This method updates the facing direction of the point object, as well as it's location.

my $p1 = Math::Shape::Point->new(0, 0, 0); #new point at 0,0 facing 0 radians.
my $p2 = Math::Shape::Point->new(1, 2, 0); #new point at 1,2 facing 0 radians.
$p1->rotate_about_point($p2, 3.14);

=head2 get_distance_to_point

Returns the distance to another point object. Requires a point object as an argument.

$p1->get_distance_to_point($p2);

=head2 get_angle_to_point

Returns the angle of another point object. Requires a point as an argument.

$p1->get_angle_to_point($p2);

=head2 get_direction_to_point

Returns the direction of another point objection as a string (front, right, back or left). Assumes a 90 degree angle per direction. Requires a point object as an argument.

$p1->get_direction_to_point($p2); # front

=head2 normalize_radian

Takes a radian argument and returns it between 0 and PI2. Negative numbers are assumed to be backwards (e.g. -1.57 == PI + PI / 2)

=head2 print_coordinates

Prints a small grid and indicates the location of the point with an '@'.

=head1 AUTHOR

David Farrell, C<< >>, L

=head1 BUGS

Please report any bugs or feature requests to C, or through
the web interface at L. I will be notified, and then you'll automatically be notified of
progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Math::Shape::Point

=head1 REPOSITORY

L

=head1 AUTHOR

David Farrell

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by David Farrell.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut