NAME

Math::Vec4 - Perl class to represent 4d vectors

TREE

-+- Math::Vector -+- Math::Vec4

REQUIRES

Math::Vec3

SEE ALSO

PDL for scientific and bulk numeric data processing and display

Math

Math::Vectors

Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

SYNOPSIS

use Math::Vec4;
my $v = new Math::Vec4;  # Make a new Vec4

my $v1 = new Math::Vec4(1,2,3);

DESCRIPTION

Default value

0 0 0

OPERATORS

Summary

'~'		=>   Returns the reverse of this vector.

'>>'		=>   Performs a clockwise rotation of the components.
'>>='		=>   Performs a clockwise rotation of the components.
'<<'		=>   Performs a counter-clockwise rotation of the components.    
'<<='		=>   Performs a counter-clockwise rotation of the components.    

'!'		=>   Returns true if the length of this vector is 0

'<'		=>   Numerical gt. Compares the length of this vector with a vector or a scalar value.
'<='		=>   Numerical le. Compares the length of this vector with a vector or a scalar value.
'>'		=>   Numerical lt. Compares the length of this vector with a vector or a scalar value.
'>='		=>   Numerical ge. Compares the length of this vector with a vector or a scalar value.
'<=>'		=>   Numerical cmp. Compares the length of this vector with a vector or a scalar value.
'=='		=>   Numerical eq. Performs a componentwise equation.
'!='		=>   Numerical ne. Performs a componentwise equation.

'lt'		=>   Stringwise lt
'le'		=>   Stringwise le
'gt'		=>   Stringwise gt
'ge'		=>   Stringwise ge
'cmp'		=>   Stringwise cmp
'eq'		=>   Stringwise eq
'ne'		=>   Stringwise ne

'bool'   	=>   Returns true if the length of this vector is not 0
'0+'		=>   Numeric conversion operator. Returns the length of this vector.

'abs'		=>   Performs a componentwise abs.
'neg' 		=>   Performs a componentwise negation.  

'++'		=>   Increment components     
'--'		=>   Decrement components     
'+='		=>   Add a vector
'-='		=>   Subtract a vector
'*='		=>   Multiply with a vector or a scalar value.
'/='		=>   Divide with a vector or a scalar value.
'**='		=>   Power
'%='		=>   Modulo fmod

'+'		=>   Add two vectors
'-'		=>   Subtract vectors
'*'		=>   Multiply this vector with a vector or a scalar value.
'/'		=>   Divide this vector with a vector or a scalar value.
'**'		=>   Returns a power of this vector.
'%'		=>   Modulo fmod
'.'		=>   Returns the dot product of two vectors.

'""'		=>   Returns a string representation of the vector.

METHODS

getDefaultValue

Get the default value as array ref

$default = $v1->getDefaultValue;
@default = @{ Math::Vec4->getDefaultValue };

$n = @{ Math::Vec4->getDefaultValue };

setX(x)

Sets the first value of the vector

$v1->setX(1);

$v1->[0] = 1;

setY(y)

Sets the second value of the vector

$v1->setY(2);

$v1->[1] = 2;

setZ(z)

Sets the third value of the vector

$v1->setZ(2);

$v1->[2] = 2;

setW(w)

Sets the fourth value of the vector

$v1->setW(2);

$v1->[3] = 2;

getReal

Returns a Math::Vec3 object.

$v3 = $v4->getReal;

getX

Returns the first value of the vector.

$x = $v1->getX;
$x = $v1->[0];

getY

Returns the second value of the vector.

$y = $v1->getY;
$y = $v1->[1];

getZ

Returns the third value of the vector.

$y = $v1->getZ;
$y = $v1->[1];

getW

Returns the fourth value of the vector.

$y = $v1->getW;
$y = $v1->[3];

negate

This is used to overload the 'neg' operator.

$v = $v1->negate;
$v = -$v1;

add(Vec4)

This is used to overload the '+' operator.

$v = $v1->add($v2);
$v = $v1 + $v2;
$v = [8, 2, 4] + $v1;
$v1 += $v2;

subtract(Vec4)

This is used to overload the '-' operator.

$v = $v1->subtract($v2);
$v = $v1 - $v2;
$v = [8, 2, 4] - $v1;
$v1 -= $v2;

multiply(Vec4 or scalar)

This is used to overload the '*' operator.

$v = $v1 * 2;
$v = $v1 * [3, 5, 4];
$v = [8, 2, 4] * $v1;
$v = $v1 * $v1;
$v1 *= 2;

$v = $v1->multiply(2);

divide(Vec4 or scalar)

This is used to overload the '/' operator.

$v = $v1 / 2;
$v1 /= 2;
$v = $v1 / [3, 7, 4];
$v = [8, 2, 4] / $v1;
$v = $v1 / $v1;	# unit vector

$v = $v1->divide(2);

dot(Vec4)

This is used to overload the '.' operator.

$s = $v1->dot($v2);
$s = $v1 . $v2;
$s = $v1 . [ 2, 3, 4 ];

cross(Vec4)

This is used to overload the 'x' operator.

$v = $v1->cross($v2);
$v = $v1 x $v2;
$v = $v1 x [ 2, 3, 4 ];

length

Returns the length of the vector This is used to overload the '0+' operator.

$l = $v1->length;

normalize

$v = $v1->normalize;

SEE ALSO

PDL for scientific and bulk numeric data processing and display

Math

Math::Vectors

Math::Color, Math::ColorRGBA, Math::Image, Math::Vec2, Math::Vec3, Math::Rotation

BUGS & SUGGESTIONS

If you run into a miscalculation, need some sort of feature or an additional holiday, or if you know of any new changes to the funky math, please drop the author a note.

ARRANGED BY

Holger Seelig holger.seelig@yahoo.de

COPYRIGHT

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