[Bf-python] High level Mathutils additions

Gilbert, Joseph jgilbert at tigr.org
Tue Dec 21 22:54:53 CET 2004


Thoughts:
I am not opposed to optimization. If a there is an implicit matrix
multiplication scheme that will be designed for the sake of optimizing
vector resizing during matrix/vector crosses then it should probably be
limited to square matrices though. This should make this an easier
project. Eq. [y] x [z][z] Also Implicit multiplication should be defined
for n-dimensional vector/matrix crosses (2D, 3D and 4D crosses with
[x][x], so as not to confuse the way VecMat and MatVec work with
different vector sizes.

The VecMat, MatVec functions could check for implicit multiplication by
verifying that Mat is a square matrix that varies in colum/row size with
the vector, and if true then does an implicit resize and multiplication.

I do worry that implicit multiplication could confuse people who didn't
realize that the vector they are multiplying is not the dimension they
expected. With error checking involved, a BPy error will be thrown
letting the user know that the vector/matrix cross they are attempting
can not be accomplished. This usually means the programmer made an error
in their script somewhere (or the data they parsed was not in the
correct format - who knows). However, with implicit multiplication this
could make this sort of error very difficult to detect. 

It would seem to me that storing the transforms for repeat use would be
a better optimization than resizing your vectors twice per calculation
though (which are usually vertices on a mesh needing to be transformed
by the same matrix). 

I think that geometric functions are great. Geometric functions never
got added because there was too much to do, but I'm glad to see someone
has the interest in adding them :) The purpose of this module is just
that - to collect useful math functions.

It would be good to see a complete set of geometric/volumetric functions
added rather then piecemeal just to get a complete overview of the
things that are required without overlap. It would be better to have
this because obsolete functions can never be deleted from BPython
without breaking compatibility with previous releases. (This also goes
for naming conventions).

-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Ted
Schundler
Sent: Tuesday, December 21, 2004 2:32 PM
To: Blender Foundation Python list
Subject: Re: [Bf-python] High level Mathutils additions

That's true. However, in CG, all you care about are the first three
items in a vector. But, in order to support translation, you need a
4th column. Blender's own internal math library supports this
mathematically impure method because it does what needs to be done
without extra jumping though hoops (though, personally I think vectors
should be stored as 4 floats in a row (and 128 bit aligned)
regardless, to make it more friendly to SSE and Altivec). But in
python, if you want to multiply a bunch of vectors by a matrix, you
have to get them as 3D, make them 4D, do the multiplication, then make
them 3D again, which is annoying. Furthermore, if you are doing this,
you are probably doing it in a loop. And in that case, a little speed
boost by skipping the unneeded steps is always nice.

That said, I think it would be a valuable addition. As for the other
operations, I assume when you say vec1,vec2,vec3, you mean points,
stored as vectors, otherwise you only need two edge vectors. And, if
you are going to add area, then you should probably add area of a quad
as well (even though it's just the area of two tris).

Intersecting of rays/edges in 3D space is a bit of a complicated
matter. With rounding, it pretty much never happens. So, you need to
make a sort of fuzzy operation. So that needs a lot of decisions on
how you handle things. For example, is the tolerance for how close
they can be a parameter? And what does it return? The line
intersection I've been using returns two scalars representing how far
along in two segments it is. So if the values are < 0 or > 1, and I'm
testing segment intersection, I know easily its out of bounds. And,
then to get the point, I calculate that later. But while that method
is good for me, it may not be as useful in other cases. So the better
question is perhaps what you need it for.

And while intersections are being discussing, ray x tri intersection
would be useful. returned value you be distance along the ray. So, if
the ray is of unit length, the returned value is the distance to the
intersection point. If they rey is representing a segment, then you
can use the >0 and <1 test to see if the segment actually intersects
with the objects. And, if you need the intersection point, you mutilpy
that scalar return value by the direction vector of the ray, and add
it to the origin point of the ray.


Ted


On Tue, 21 Dec 2004 13:42:23 -0500, Gilbert, Joseph <jgilbert at tigr.org>
wrote:
> You technical can't multiply a 3 dimensional vector by a 4x4
dimensional
> matrix. You can pre- and post- multiply a 3 dimensional vector by a
3x4
> and 4x3 dimensional matrix. The results of a [3] x [4][4] is
undefined.
> The issue of making copies because the data in the vector is not a
> referenced pointer is something Stephan can address.
_______________________________________________
Bf-python mailing list
Bf-python at projects.blender.org
http://projects.blender.org/mailman/listinfo/bf-python



More information about the Bf-python mailing list