Rectangle
Rectangles in 3d space
PhilipRBrenan@yahoo.com, 2004, Perl License
Synopsis
Example t/rectangle.t
#_ Rectangle __________________________________________________________
# Test 3d rectangles
# philiprbrenan@yahoo.com, 2004, Perl License
#______________________________________________________________________
use Math::Zap::Rectangle;
use Math::Zap::Vector;
use Test::Simple tests=>3;
my ($a, $b, $c, $d) =
(vector(0, 0, +1),
vector(0, -1.9, -1),
vector(0, -2.0, -1),
vector(0, -2.1, -1)
);
my $r = rectangle
(vector(-1,-1, 0),
vector( 2, 0, 0),
vector( 0, 2, 0)
);
ok($r->intersects($a, $b) == 1);
ok($r->intersects($a, $c) == 1);
ok($r->intersects($a, $d) == 0);
Description
Rectangles in 3d space
Constructors
new
Create a rectangle from 3 vectors:
a position of any corner
b first side
c second side.
Note that vectors b,c must be at right angles to each other.
rectangle
Create a rectangle from 3 vectors - synonym for "new".
Methods
check
Check its a rectangle
is
Test its a rectangle
a,b,c
Components of rectangle
clone
Create a rectangle from another rectangle
accuracy
Get/Set accuracy for comparisons
intersection
Intersect line between two vectors with plane defined by a rectangle
r rectangle
a start vector
b end vector
Solve the simultaneous equations of the plane defined by the rectangle and the line between the vectors:
ra+l*rb+m*rc = a+(b-a)*n
=>ra+l*rb+m*rc+n*(a-b) = a-ra
Note: no checks (yet) for line parallel to plane.
intersects
# Test whether a line between two vectors intersects a rectangle # Note: no checks (yet) for line parallel to plane.
visible
# Visibility of a rectangle r hid by other rectangles R from a view # point p. # Rectangle r is divided up into I*J sub rectangles: each sub rectangle # is tested for visibility from point p via the intervening rectangles.
project
# Project rectangle r onto rectangle R from a point p
projectInto
# Project rectangle r into rectangle R from a point p
Exports
Export "rectangle"
Credits
Author
philiprbrenan@yahoo.com
Copyright
philiprbrenan@yahoo.com, 2004
License
Perl License.