The manual says that cross() is only valid on 3d vectors, but it seems that
if you give it 2d input it extends them into 3d vectors in the plane and
returns the length of the resulting cross product.
So
echo(cross([1,2],[5,6]));
echo(cross([1,2,0],[5,6,0]));
produces the output:
ECHO: -4
ECHO: [0, 0, -4]
Is this an intentional behavior that we can rely upon?
--
Sent from: http://forum.openscad.org/
As far as I know,
cross([x, y], [u, v]) == [-y, x][u, v] == [x,y][v,-u] == xv - yu
It is the scalar product of the first vector by a 90 degree rotation of the
second. It is useful to check collinearity and whether three points in a
list is CCW, to compute area and the determinant of a 2D matrix, etc. The
3D cross product can be expressed by three 2D cross products:
cross([x,y,z], [u,v,w]) == [ cross([y,z], [v,w]), cross([u,w], [x,z]),
cross([x,y], [u,v]) ]
As it is not documented in the manual, your question is relevant and I
expect the answer to be yes!
Em ter., 9 de jun. de 2020 às 19:47, adrianv avm4@cornell.edu escreveu:
The manual says that cross() is only valid on 3d vectors, but it seems that
if you give it 2d input it extends them into 3d vectors in the plane and
returns the length of the resulting cross product.
So
echo(cross([1,2],[5,6]));
echo(cross([1,2,0],[5,6,0]));
produces the output:
ECHO: -4
ECHO: [0, 0, -4]
Is this an intentional behavior that we can rely upon?
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
No answer. Who is in silence agrees, they say.
I have found a reference of a 2D cross product in an OpenSCAD regression
test:
https://github.com/openscad/openscad/blob/master/testdata/scad/functions/cross-tests.scad
.
So, it seems it is not accidental. And, as someone said before, what is in
the regression tests is what holds.
That said, we can update the manual with the information about 2D cross.
Em qua., 10 de jun. de 2020 às 00:12, Ronaldo Persiano <
rcmpersiano@gmail.com> escreveu:
As far as I know,
cross([x, y], [u, v]) == [-y, x][u, v] == [x,y][v,-u] == xv - yu
It is the scalar product of the first vector by a 90 degree rotation of
the second. It is useful to check collinearity and whether three points in
a list is CCW, to compute area and the determinant of a 2D matrix, etc. The
3D cross product can be expressed by three 2D cross products:
cross([x,y,z], [u,v,w]) == [ cross([y,z], [v,w]), cross([u,w], [x,z]),
cross([x,y], [u,v]) ]
As it is not documented in the manual, your question is relevant and I
expect the answer to be yes!
Em ter., 9 de jun. de 2020 às 19:47, adrianv avm4@cornell.edu escreveu:
The manual says that cross() is only valid on 3d vectors, but it seems
that
if you give it 2d input it extends them into 3d vectors in the plane and
returns the length of the resulting cross product.
So
echo(cross([1,2],[5,6]));
echo(cross([1,2,0],[5,6,0]));
produces the output:
ECHO: -4
ECHO: [0, 0, -4]
Is this an intentional behavior that we can rely upon?
--
Sent from: http://forum.openscad.org/
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org