Math-Project3D
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Math/Project3D.pm view on Meta::CPAN
$col = $col->[0];
$rows[$_][$cn] = $col->[$_][0] for 0..$num_rows-1;
}
else {
$rows[$_][$cn] = $col->[$_] for 0..$num_rows-1;
}
$cn++;
}
return bless [
\@rows,
$num_rows,
$num_cols,
undef,
undef,
undef
] => $class;
}
# class and object method new_function
#
# Wrapper around Math::Project3D->new()
# Returns compiled function (anon sub)
# As a class method, it does not have side effects.
# As an object method, it assigns the returned function to
# the object's function attribute.
sub new_function {
@_ > 1 or croak "No arguments supplied to 'new_function' method.";
my $self = shift;
my @components = @_;
my $function = Math::Project3D::Function->new(@components);
if (ref $self eq __PACKAGE__) {
$self->{function} = $function;
}
return $function;
}
# Class and object method/constructor new
#
# Arguments are used in the object's anon hash.
# Creates new object.
# Returns MP3D instance.
sub new {
my $proto = shift;
my $class = ref $proto || $proto;
# !!!FIXME!!! Insert argument checking here
my $self = {
function => undef,
@_
};
bless $self => $class;
# Some attributes are required.
my $missing_attribute = $self->_require_attributes(qw(
plane_basis_vector
plane_direction1
plane_direction2
));
croak "Required attribute '$missing_attribute' missing."
if defined $missing_attribute;
# Transform the vector/matrix specifications ((nested) array refs)
# into Math::MatrixReal's.
foreach ( qw(
plane_basis_vector
plane_direction1
plane_direction2
) ) {
# Argument checking, we either want an array ref or a MMR object.
croak "Invalid argument '$_' passed to new. Should be an array reference."
if not exists $self->{$_};
next if ref $self->{$_} eq 'Math::MatrixReal';
croak "Invalid argument '$_' passed to new. Should be an array reference."
if ref $self->{$_} ne 'ARRAY';
# Transform into an MMR object.
$self->{$_} = $self->_make_matrix($self->{$_});
}
# Projection vector defaults to the normal vector of the plane,
# but may also be specified explicitly as array ref or MMR object.
if ( defined $self->{projection_vector} and
ref $self->{projection_vector} eq 'ARRAY' ) {
$self->{projection_vector} = $self->_make_matrix( $self->{projection_vector} );
} elsif ( not defined $self->{projection_vector} or
ref $self->{projection_vector} ne 'Math::MatrixReal' ) {
# Defaults to the normal of the plane.
$self->{projection_vector} = $self->{plane_direction1}->vector_product(
$self->{plane_direction2}
);
}
# Now generate the linear equation system that has to be solved by
# MMR in order to do project a point onto the plane.
#
# MMR does all the dirty work. (Thanks!) So we just create a matrix.
# (d, e be the directional vectors, n the vector we project along,
# p the basis point. Let i be the solution)
#
# x(t) + n1*i1 = d1*i2 + e1*i3 + p1
# y(t) + n2*i1 = d2*i2 + e2*i3 + p2
# z(t) + n3*i1 = d3*i2 + e3*i3 + p3
#
# This is the intersection of the plane and the corresponding orthogonal
# line through s(t). Another form:
#
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.163 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )