and 1 contributors

# NAME

Math::Geometry::Multidimensional - geometrical functions in n-dimensions

Version 0.02

# SYNOPSIS

This module has a bunch of functions that work in mulitiple dimensions, e.g. distance of a point from a line in n-dimensions.

``````    use Math::Geometry::Multidimensional qw/distanceToLineN/;
# parametric:
my \$distance = distanceToLineN(\$point, \$gradients, \$intersect);
# symmetric:
my \$distance = distanceToLineP(\$point, \$denominators, \$constants);
``````

# EXPORT

distanceToLineN
diagonalComponentsN
diagonalDistancesFromOriginN

# SUBROUTINES/METHODS

## distanceToLineN

We have a line with symmetric form:

(x+a)/m = (y+b)/n = (z+c)/p ...

@M is the list of denominators and @C is the list of constants.

For a point \$P,

``        distanceToLineN(\$P,\@M,\@C)``

returns the distance to the closest point on the line... in n-dimensions.

## diagonalDistanceFromOriginN

This is the distance along the y=z=x=... line from any point to the origin. First we find the closest point on y=z=x=... from our point, which happens to be the average of the coordinates, e.g. if the point is (10,8) then the closest point on y=z is 9,9. If the point is (9,8,4) then the closest point on z=y=x is (7,7,7). If the point is (2,3,4,7) then the closest point on z=y=x=w is (4,4,4,4). Why?

For P(u,v,w) and L: (x+a)/k = (y+b)/l = (z+c)/m = t

we know that x=kt-a ; y=lt-b ; z=my-c

so k(kt-a) + l(lt-b) + m(mt-c) = kkt-ka + llt-lb + mmt-mc = ku+lv+mw OR t(kk+ll+mm) = k(u+a)+l(v+b)+m(w+c) so t = (k(u+a)+l(v+b)+m(w+c)) / (kk+ll+mm)

BUT, if a=b=c=0 and k=l=m=1, then:

t = (x+y+z)/(3)

in general, t is the average of the coordinates.

then, x' = kt-a, and if k is 1 and a is 0, then x' is t.

P' is (t,t,t) so the distance to P' from the origin is sqrt(3 t^2) or sqrt( 3 * ((x+y+z)/3)^2) or sqrt( 3 * (x+y+z)^2 / 9 ) or sqrt( (x+y+z)^2 / 3) or (x+y+z)/sqrt(3) or SUM(coords)/sqrt(n)

Does that make sense?

## diagonalDistancesFromOriginN

Acts on columns rather than an individual point... give it column number, row number and list of columns.

``        my \$arrayref = diagonalDistancesFromOriginN (\$k,\$n,@cols)``

## diagonalComponentsN

Here, we are basically rotating all the data so that the "y-axis" or whatever you want to call the left-most co-ordinate now lies diagonally through the data.

## distanceFromDiagonalN

As above, we know that the point P' on the diagonal closest to our point P has the average coordinates of point P. And the distance PP' (x-x', y-y', z-z') is the root of the sum of the squares. So

so, if x' = t, which is (x+y+z)/3 ...

PP' = sqrt( (x - x/3 - y/3 - z/3)^2 + (y - x/3 - y/3 - z/3)^2 + (z + x/3 + y/3 + z/3)^2 )

= sqrt( x^2 (2/3) + y^2 (2/3) + z^2 (2/3) + 2xy + 2xz + 2yz )

this is not implemented yet.

# AUTHOR

Jimi Wills, `<jimi at webu.co.uk>`

# BUGS

Please report any bugs or feature requests to `bug-math-geometry-multidimensional at rt.cpan.org`, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Math-Geometry-Multidimensional. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

# SUPPORT

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

``    perldoc Math::Geometry::Multidimensional``

You can also look for information at:

# ACKNOWLEDGEMENTS

Copyright 2013 Jimi Wills.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: