[Bf-python] High level Mathutils additions

Ted Schundler tschundler at gmail.com
Tue Dec 21 20:32:00 CET 2004


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.



More information about the Bf-python mailing list