On 8/9/06, Brian Schott <[EMAIL PROTECTED]> wrote:
I did not know that the determinant had such an
interpretation (signed area of a triangle).
...
I was not aware that a determinant was defined for a
nonsquare matrix, which Boyko defines. With that in mind I
redefined Boyko's formula to omit the third (0 0) point and
think I get the same result as the original forumla.
...
But the more important question regarding Boyko's
solution is, how can we make the leap from my original
problem definition to the signed area of a triangle?
Brian,
In my yesterday's posts I was too busy doing other things,
and probably too terse to be clear. Meanwhile others
pointed to some related facts, but maybe I should still
explain in detail what I meant. Here it is.
As you noticed, if
det =. -/ . *
and you omit 0 0 and only compute det B,:A , you would
get the same result. And indeed determinant in mathematics
only makes sense for square matrices. For the above case,
we are computing the doubled oriented area of the triangle
OAB. (To be precise, that is actually the *negated* area
-- that of OBA -- because I wanted `positive' to mean `A is
left'.)
On the other hand, the presence of 0 0 in what I wrote
was to suggest that you can actually take any point, say
X, instead of O(0,0), and you will still be computing the
oriented area of a triangle. Namely, consider three planar
points
'A B C' =. Ax Ay; Bx By; Cx Cy
From linear algebra, the determinant of the matrix
Ax Ay 1, Bx By 1,: Cx Cy 1 (of shape 3 3), or
equivalently that of (B-A),:C-A (of shape 2 2)
is twice the oriented area of the triangle ABC.
(See a note at the end about why it is so.)
So if the determinant is positive, A, B, and C are
counterclockwise and thus, if you are looking from
A, then B is to the right of C (and C is to the right
of A from B, and A is to the right of B from C.)
Now, with respect to J, the interesting fact is that,
although A,B,:C is of shape 3 2, the expression
det A,B,:C
correctly computes the same oriented area of ABC.
I discovered for myself this behaviour of J several
years ago. To my knowledge, it is not documented.
Apparently J computes `determinants' of matrices of
any shape. At least it does not object to. :)
So, e.g.:
'A B C'=. 1 0; 2 1; 2 5
det A,B,:C
4
It is somewhat curious that the area of a quadrangle
ABCD can be computed with a formula as simple as for
a triangle, namely -:(C-A),:D-B (that easily follows
from the triangle formula).
How about higher dimensions? For spacial points:
'A B C D'=. 9 8 7; 3 2 1; 4 5 6; 10 2 3
det A,B,C,:D
108
(a det of a (4 3)-shaped matrix).
The obtained value is 6 times the oriented volume of the
tetrahedron ABCD. The value is positive when, looking
from, say D, the (spacial) triangle ABC is a *negative*,
i.e. clockwise-oriented triple (and similarly if you look
from another apex).
Similar facts hold for higher dimensions (if that is
of interest): the hypervolumes that det gives should
be divided by !n, where n is the number of dimensions
of the hyperspace.
We can go to a lower dimension, too.
'A B'=. 2; 5
det A,:B
_3
is an example of expensively computing a difference between
two numbers (or the oriented length of the segment between
two points in an one-dimensional space).
~~~~~~
P.S.: Why does -: det (B-A),:C-A equal the oriented area
of the triangle ABC?
B-A and C-A are two of the sides of ABC. Let their lengths
be c and b, respectively, and let
'x1 y1'=. B-A
'x2 y2'=. C-A
The determinant equals (x1*y2)-x2*y1 , which is the scalar
product of -y1 x1 and x2 y2 .
-y1 x1 is a vector of the same length as B-A and
rotated at 90 degrees w.r.t. the latter. Because the
scalar product also equals b*c*COS, where COS is the cosine
between -y1 x1 and x2 y2 , it also equals b*c*SIN where
SIN is the sine of the complementary to 90 degrees angle.
However, b*SIN equals h -- the distance from C to AB, and
so, finally, -: det (B-A),:C-A equals -:c*h, which,
as known from school geometry, is the area of ABC.
Well, I have brushed under the carpet the sign of COS (and
SIN), but it is not difficult to figure out that the cosine
(hence the area) is positive when the corresponding angle
is within 90 degrees, which means B-A is to the right of C-A.
Boyko
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm