Skip to content.

Sections
Personal tools
You are here: Home » ダウンロード » vecmath_package(英)

Document Actions

unficial Java3 vecmath package

by Kenji Hiranabe(since 11/27,1997)

[Japanese Version Available]


This is unofficial implementation(java source code) of the javax.vecmath package specified in the Java(TM) 3D API 1.2
The package includes classes for 3-space vector/point, 4-space vector, 4x4, 3x3 matrix, quaternion, axis-angle combination and etc. which are often utilized for computer graphics mathematics. Most of the classes have single and double precision versions. Generic matrices' LU and SV decomposition are also there.

This is Free software, provided AS IS, with NO WARRANTY. Bug reports, comments are welcome.

Note that this implementation corresponds to Java3D 1.2 specification. My implementation has full specification implemented and has full source code.

Download API 1.2 Java(tm)

C++ port

NEWNow supports Visual C++ 6.0

I decide to port this javax.vecmath package to C++ because the parallel C++ version can make a FAST vector/matrix package by the original Java3D specification's unique natures. Java3D designers decided to;

  1. Make all member variables 'public'.
  2. Make all methods(member functions) 'final' (non-virtual)
  3. Avoid using arrays in Matrices and Vectors.
  4. Distiguish Points from Vectors as different classes.

Design decision (1)-(3) are from Java's inherent speed problem. (1) looks like a bad approach in object-orientation and thread-safy sence, but if neccesary, encapsulation can be done by wrapper classes (Java3D does have wrappers for their SceneGraph use). (2) can cause subclassing problems, but since each method does an apparent and natural job, the semantics can be kept consistent. (3) can make a code bloat problem because no for/while loop with array indexing is in the library code. But I found it not so bad after I tried implementation, and it makes this library FAST.(4) was a very good decision. This makes your programs semanticly consistent and increases readabilty.

Luckly, these four points makes this parallel C++ library very unique. Highest priority to time efficiency. i.e. no 'virtual' calls, no 'new's, extensively inlined templates, public members, and para-phrazed calculation(no loops and array indexing in methods).

For example, not having an array representation in Matrices, the determinant of Matrix3 is coded as;

template < class T >
T Matrix3 < T >::determinant() const {
    // I believe this is the fastest way, less calculation and no indexing.
    return m00*(m11*m22 - m21*m12)
        - m01*(m10*m22 - m20*m12)
        + m02*(m10*m21 - m20*m11);
}

Off cource there are shortcomings in this C++ package.

  • Element access by index is slow.

'operatoer[]' is not supported intensionally, because this can lead to a programming style which can cause a performance problem.

     // a bad user program
     Vector3d u(1,2,3), v;
     Matrix3d m(1,2,3,4,5,6,7,8,9);

     //  this can be very slow
     for (unsigned i = 0; i < 3; i++)
        for (unsigned j = 0; j < 3; j++)
            v[i] = m(i,j)*u[j];

This syntax could be supported in the library, but you should use METHODs.

     m.transform(u, &v);   // much faster

         or

     v = m*u;              // others like this style better.

which are much faster, and readable. A lot of methods are prepared so that users don't have to access elements directly.

Other features of the C++ package are;

  • All code is in *.h file. No need to compile. You can just place them and include them.
  • By customising "vm_conf.h", you can include/exclude io supports for < iostream.h >. If you includes io support, you can code like;
        Matrix3 m();
        cout << m;
    
  • By customising "vm_conf.h", you can include/exclude string supports for < string >, If you includes string support, you can code like;
        string s = m.toString();
    
    And you can intensionally exclude these support for a compact version and less include files in compile time.
  • All classes have 'hashCode' methods and there is a 'VmHash' class, which can be used with hash_map in SGI STL(Standard Template Library).

Download API 1.2 C++ port

Links

  • Specifications
  • Projects
  • Documents
  • Link Sites

  • [Feedback]
    * Mail to: hiranabe@esm.co.jp