Vector::Object3D::Line - Three-dimensional line object definitions
use Vector::Object3D::Line; # Create two endpoints of a line: my $vertex1 = Vector::Object3D::Point->new(x => 3, y => -2, z => 1); my $vertex2 = Vector::Object3D::Point->new(x => -1, y => 2, z => 3); # Create an instance of a class: my $line = Vector::Object3D::Line->new(vertex1 => $vertex1, vertex2 => $vertex2); my $line = Vector::Object3D::Line->new(vertices => [$vertex1, $vertex2]); # Create a new object as a copy of an existing object: my $copy = $line->copy; # Get first vertex point: my $vertex1 = $line->get_vertex1; # Get last vertex point: my $vertex2 = $line->get_vertex2; # Get both vertex points: my @vertices = $line->get_vertices; # Print out formatted line data: $line->print(fh => $fh, precision => $precision); # Compare two line objects: my $are_the_same = $line1 == $line2;
Vector::Object3D::Line provides an abstraction layer for describing line object in a three-dimensional space by composing it from two Vector::Object3D::Point objects (referred onwards as vertices).
Vector::Object3D::Line
Vector::Object3D::Point
Create an instance of a Vector::Object3D::Line class:
my $vertex1 = Vector::Object3D::Point->new(x => 3, y => -2, z => 1); my $vertex2 = Vector::Object3D::Point->new(x => -1, y => 2, z => 3); my $line = Vector::Object3D::Line->new(vertex1 => $vertex1, vertex2 => $vertex2); my $line = Vector::Object3D::Line->new(vertices => [$vertex1, $vertex2]);
There are two individual means of Vector::Object3D::Line object construction, provided a hash of two vertex components or a list of two point objects. When present, vertices constructor parameter takes precedence over vertex1 and vertex2 points in case both values are provided at the same time.
vertices
vertex1
vertex2
Vector::Object3D::Line requires provision of two endpoints in order to successfully construct an object instance, there is no exception from this rule.
Create a new Vector::Object3D::Line object as a copy of an existing object:
my $copy = $line->copy;
Get first vertex point:
my $vertex1 = $line->get_vertex1;
Get last vertex point:
my $vertex2 = $line->get_vertex2;
Get both vertex points:
my @vertices = $line->get_vertices;
Print out text-formatted line data (which might be, for instance, useful for debugging purposes):
$line->print(fh => $fh, precision => $precision);
fh defaults to the standard output. precision is intended for internal use by string format specifier that outputs individual point coordinates as decimal floating points, and defaults to 2 (unless adjusted individually for each vertex).
fh
precision
Compare two line objects:
my $are_the_same = $line1 == $line2;
Overloaded comparison operator evaluates to true whenever two line objects are identical (both their endpoints are located at exactly same positions, note that vertex order matters as well).
my $are_not_the_same = $line1 != $line2;
Overloaded negative comparison operator evaluates to true whenever two line objects differ (any of their coordinates do not match).
There are no known bugs at the moment. Please report any bugs or feature requests.
Vector::Object3D::Line exports nothing neither by default nor explicitly.
Vector::Object3D, Vector::Object3D::Point.
Pawel Krol, <pawelkrol@cpan.org>.
Version 0.01 (2012-12-24)
Copyright (C) 2012 by Pawel Krol.
This library is free open source software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
PLEASE NOTE THAT IT COMES WITHOUT A WARRANTY OF ANY KIND!
To install Vector::Object3D, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Vector::Object3D
CPAN shell
perl -MCPAN -e shell install Vector::Object3D
For more information on module installation, please visit the detailed CPAN module installation guide.