Ah, yes. The idea of using a static helper function is neat.
It also struck me as odd that none of the Tuple* functions returns the
result of its calculations (apart from angle(), dot() etc. which
return a scalar). Perhaps this is a way of avoiding the inevitable
(a.add(b.sub(c))).cross(e.sub(f.scaleAdd(2, g))
which is a pain to read and maintain. I know there have been
discussions regarding the readability of this method versus that
produced by operator overloading, e.g.
(a + (b-c)) * (e - (2*f + g))
but I would sometimes find it useful to do the calculation "in place"
rather than create a new object to temporarily hold the result.
Also, why does scaleAdd() assume I want to scale the first tuple
before adding the second (i.e. this = s*this + t1) rather than scaling
the second tuple and adding it to the first, i.e. this = this + s*t1
In order to do that I have to resort to the messy
t1.scaleAdd(s, t2, t1)
Just a thought.
> Ah, you are right. I was to much focussed on geometry.
>
[quoted text clipped - 18 lines]
> Regards
> JK.
Comments inline:
> Ah, yes. The idea of using a static helper function is neat.
>
[quoted text clipped - 12 lines]
> but I would sometimes find it useful to do the calculation "in place"
> rather than create a new object to temporarily hold the result.
Well, in your example temporary vectors are also created, but
implicitly. Where else should the result of e.g. (b-c) be stored? I
think the idea in Java3D is memory efficiency. With Java3D you have full
control of how many objects are created. The garbage collector would
have lot of work deallocating all the temporary tuples, whose very small
size might also result in horrible fragmentation.
Another argument is, that Java3D is somehow derived from OpenInventor,
which is C++, i.e. does not have garbage collection at all.
Have you ever tried to do vector calculations in C++? Sure, it does
provide operator overloading, therefore you can implement vector
calculations using "+" etc. The problem is efficiency and the lack of a
garbage collector: To avoid memory leaks, the result of an "operator+"
for example must be a Vector and not a reference to one. That means,
after calculating the sum of the vectors the result must be copied to a
temporary automatic variable. Even in your small example there are 5
operations which would require a temporary variable and copying results.
As a last point, Java is object oriented. Let's look at a small example
with vectors x,y and z
x=y+z
Which method is required to do this? Thinking "object oriented", meaning
an object's state is only modified by calling its methods, results in a
method of x, which is the only variable that changes state (value). So
they put
x.add(y,z)
into the Java3D API.
> Also, why does scaleAdd() assume I want to scale the first tuple
> before adding the second (i.e. this = s*this + t1) rather than scaling
[quoted text clipped - 4 lines]
>
> Just a thought.
Yes, very strange indeed. The reason might be the historical SAXPY
operation in the Fortran BLAS (basic linear algebra subroutines)
library. SAXPY stands for "(single precision) a*x + b"
Regards
JK.