After learning how to build and display spheres in 3D with ImageJ [see post], this post describes how we can use them for drawing a 3D curve...
The purpose is to draw a 3D curve with a tubular shape composed of many merged spheres. As an example of 3D curve, torus solenoids [Link] are really nice and one of them is represented in Fig.1. They are defined by the following formula:
x = (a + b . cos(nt) ) . cos(t)y = (a + b . cos(nt) ) . sin(t)z = b . sin(t)where n = p/qa and b are the torus outer and inner radii, respectively
Fig.1: Toric solenoid with p/q = 9/2 rendered by Plugins > 3D > Volume Viewer with the Fire LUT and Volume II (slow) renderer. |
Fig.2: Toric solenoids calculated with n = 5/2, 2/5, and 7/3, respectively. |
Implementation
The algorithm is exactly the same as the random spheres [see post]: a sphere is created as a template (line 29) and then is duplicated and moved according to the curve formula (lines 31-37). The implementation is based on our functions initSphere(...) and translate(...) previously described [here].A dialog box (lines 17-22) is displayed to define the variables p and q used to modify the shape of the curve. Moreover, for sake of simplicity, the other parameters (volume size, sphere radius, outer and inner radii of torus, etc.) are hard-coded (lines 6-13).
The tricky part is the step (by default, 0.05) used to create a continuous smooth pipe (line 32). If your step is too large (e.g. 1.5), the spheres are easily identified and the 3D curve doesn't look nice otherwise, if it's too small, you create too much unneeded spheres and your script is slow.
Here is the IJ macro/script.
+++ IJ snippet +++ +++ End of IJ snippet +++
No comments:
Post a Comment