Generating and Displaying 3D Vector-format files

The first example is shown here in a parallel-projected spiral form using dxfviewer-swing.jar. It can be scaled, translated and rotated on-screen in real-time.

The code-section that generates this path is..
 xs =0: ys =0: zs =0

for i =1 to 40 step 0.02   '   about six revolutions- 40 radians.
    xf =i *sin( i)
    yf =i *cos( i)
    zf =i
    call makeLine xs, ys, zs, xf, yf, zf
    xs =xf: ys =yf: zs =zf
next i

This rotates a point around a circle of steadily increasing radius, ie ( r sin( i), r cos( i)) while steadily moving along the z-axis.

3D vector files

Mathematically-generated curves in 2D and 3D are easily output from your chosen language- LB in my case. Initially I was generating my own projections and axis display, but this is complex to program and quite slow unless programmed in a lower-level language. The big advantage is that you can change /improve anything you like- eg colour-code or alter the width of lines or axes; colour backgrounds; 'fog' the further-away lines; or generate an animated GIF from a sequence of views.

Vector specification of a 2D or 3D object enables its reconstruction on a screen at full resolution even when magnified. Rather than invent my own formats, I use SVG files for 2D objects and now a simple early AutoCAD format for 3D objects. It is very forgiving- you can use LF or CRLF; leading spaces are optional; etc. But there is no guarantee that all- or even most- DXF viewers will not barf at it...

DXF files can be plain-text. A number signals what the next line will hold- eg 999 that it is a REM line, 0 that it is a descriptor. 10, 20 and 30 precede the x y and z-start values. 11, 21 and 31 the x, y and z-finish values. The DXF file for the above curve is ...

  0
SECTION
  2
HEADER
  999
DXF file created by JohnF.
  999
Data calc'd by Liberty BASIC
  0
ENDSEC
  0
SECTION
  2
TABLES
  0
ENDSEC
  0
SECTION
  2
BLOCKS
  0
ENDSEC
  0
SECTION
  2
ENTITIES   ...... everything before here is set-up preamble......
  0        ...... here we specify the start and end of first line-segment as ( x, y, z)
LINE
  8
  0
 10
  0			xs =0
 20
  0         ys =0
 30
  0         zs =0
 11
  1.67685511    xf =1.676..
 21
  0.60517204    yf =0.605...
 31
  1             zf =1
  0
LINE
 ............................
 etc  for all the other segments
 etc
 ............................
  0
ENDSEC
  0
EOF

This was all stimulated by discovering that a freely-available JAVA jar-file could display the results and rotate them in real-time.

Code for this version follows. I'd usually save & re-load the preamble as a file. Many things still to try, including file-selectors & GUI text-editor front-end to accept the code-section that creates the paths & code to run/evaluate it and display.


nomainwin

LF$ =chr$( 10)

open "outputspiral.dxf" for output as #outFile

preambleDXF$ ="  0" +LF$ +"SECTION" +LF$ +"  2" +LF$ +"HEADER" +LF$ +"  999" +LF$ +_
              "DXF file created by JohnF." +LF$ +"  999" +LF$ +"Data calc'd by Liberty BASIC" +_
              LF$ +"  0" +LF$ +"ENDSEC" +LF$ +"  0" +LF$ +"SECTION" +LF$ +"  2" +_
              LF$ +"TABLES" +LF$ +"  0" +LF$ +"ENDSEC" +LF$ +"  0" +LF$ +"SECTION" +_
              LF$ +"  2" +LF$ +"BLOCKS" +LF$ +"  0" +LF$ +"ENDSEC" +LF$ +"  0" +_
              LF$ +"SECTION" +LF$ +"  2" +LF$ +"ENTITIES" +LF$
#outFile, preambleDXF$;

xs =0: ys =0: zs =0

for i =1 to 40 step 0.1
    xf =i *sin( i)
    yf =i *cos( i)
    zf =i
    call makeLine xs, ys, zs, xf, yf, zf
    xs =xf: ys =yf: zs =zf
next i

terminateDXF$ ="  0" +LF$ +"ENDSEC" +LF$ +"  0" +LF$ +"EOF" +LF$
#outFile, terminateDXF$

close #outFile

run "dxfviewer-swing.jar outputspiral.dxf"

end

sub makeLine xs, ys, zs, xf, yf, zf
    #outFile, "  0" +LF$
    #outFile, "LINE" +LF$
    #outFile, "  8" +LF$
    #outFile, "  0" +LF$
    #outFile, " 10" +LF$
    #outFile, "  " +str$( xs) +LF$
    #outFile, " 20" +LF$
    #outFile, "  " +str$( ys) +LF$
    #outFile, " 30" +LF$
    #outFile, "  " +str$( zs) +LF$
    #outFile, " 11" +LF$
    #outFile, "  " +str$( xf) +LF$
    #outFile, " 21" +LF$
    #outFile, "  " +str$( yf) +LF$
    #outFile, " 31" +LF$
    #outFile, "  " +str$( zf) +LF$
end sub

I can be contacted as mr dot john dot f at gmail dot com