The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::Vector - Abstract base class for vector classes

TREE

-+- Math::Vector

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

        package Math::VecX;
        use base 'Math::Vector';
        use constant getDefaultValue => [ 0, 0 ];
        1;

DESCRIPTION

OPERATORS

Summary

        '&'             =>   Performs a componentwise and.
        '|'             =>   Performs a componentwise or.
        '^'             =>   Performs a componentwise xor.

        '<<'            =>   Left shift.
        '>>'            =>   Right shift.

        '!'             =>   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
        
        'int'           =>   Performs a componentwise int.
        'abs'           =>   Performs a componentwise abs.
        
        '""'            =>   Returns a string representation of the vector.

METHODS

new

        my $b = new Math::VecX;                                           
        my $c = new Math::VecX(1,2, @a);
        my @d = @$c; 
        

If you call new() with a reference to an array, it is used as reference internally.

        my $f = new Math::VecX([1,2, @a]); 

copy

Makes a copy

        $c = $v->copy;

getValue

Returns the value of the vector as array.

        @v = $v1->getValue;

setValue(x,y,z)

Sets the value of the vector

        $v1->setValue(1,2);

rotate(steps)

Performs a componentwise rotation. A positiv number performs a clockwise rotation. A negativ number performs a counter-clockwise rotation.

        $v = $vec->rotate(1);
        $v = $vec->rotate(2);

sig

Performs a componentwise sig.

        $v = new Math::VecX(-4, 5);
        $v = $VecX->sig;
        printf $v;         # -1 1

sum

Returns the sum of the components.

        $v = new Math::VecX(-8, 2);
        $s = $VecX->sum;
        printf $s;         # -6

normalize

        $v = $v1->normalize;

toString

Returns a string representation of the vector. This is used to overload the '""' operator, so that vector may be freely interpolated in strings.

        my $q = new Math::VecX(1,2);
        print $q->toString;                # "1 2"
        print "$q";                        # "1 2"

BUGS & SUGGESTIONS

If you run into a miscalculation 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.