We are now ready to discuss the three-ellipsoid-particles component that we introduced in ThreeGraphicsPanel.vue. Recall that the template has the following form:
The ellipsoid particles component
The file ThreeEllipsoidParticles.vue also does not contain any information inside the <template> tags and contains the following:
However, the source code contains more - as you can see below.
There are several aspects that need consideration in this code.
We use the watch “instance method” of Vuex to make sure that the particles are added to the scene only after the particle file has been read.
In this example we do not stop watching the variable particleReadComplete (see Part 2 for details) after the particle data has been converted and saved. However, that step is highly recommended.
Creating the ellipsoid particles
The particle axis data are in the form of angles between the ellipsoid axes and the world coordinate axes. These are converted directly into the appropriate rotation matrix. Sphere objects are then created at the origin, rotated, scaled, and translated to their actual positions. The sphere objects are then transformed into SphereBufferGeometry objects to make their manipulation slightly more efficient. Finally, a “material” shading model is added to make sure that the image displayed isn’t flat and a triangulated mesh is generated for each object.
The rotation matrix performs a transformation of the form We want to rotate the world coordinate vectors , , , into vectors that are aligned with the ellipsoid axes, , , . Therefore, we need to find a rotation matrix such that where . Taking dot products of both sides with , we get Now, . So we have . Therefore, .
Let us look at the ellipsoid axis vector . This vector has components where , , and . That is why we can create the rotation matrix directly from the axis data in the code sample.
A plot of the ellipsoids produced by our code can be seen below.
In the next part of this series we will explore how vtk.js can be used to do the same plot.
If you have questions/comments/corrections, please contact banerjee at parresianz dot com dot zen (without the dot zen).