Convert Script

#!/usr/bin/perl

# Open a file that contains x + y values of airfoil section
open F, "

# Read file into an array of lines. Chomp off the newline
while (){
  chomp;
  push @a, $_;
}

# Open an output file for povray vertices's
open O, ">vertices.inc" or die "Could not open output file!";

# Based on the size of the array, calculate the number of
# vertice vectors we are going to create and print to file
$n = ($#a + 1)*2;
print O "$n";

# Iterate the array and output section in Pov friendly vectors
# This will be the root section
for $i (0 .. $#a){
  ($x, $y) = split(' ', $a[$i]);
  print O ",\n<$x, $y, 0>";
}

# Do it again, this time scale for tip section
for $i (0 .. $#a){
  ($x, $y) = split(' ', $a[$i]);
  $x = ($x * 0.5)+1.5;
  $y = ($y * 0.5);
  print O ",\n<$x, $y, 2>";
}

# Close our files
close F;
close O;

# Open a new file for the faces
open O, ">faces.inc" or die "Could not open output file!";
$k1 = 0;

# Number of faces based on number of vertices's, and print
# to file.
$o = $n-2;
print O "$o";

# Create povray faces for use in mesh object
while ($k1 < ($n/2)-1){
  $k2 = $k1+61;
  $k3 = $k1+1;
  $k4 = $k1+62;
  print O ",\n<$k1, $k2, $k3>";
  print O ",\n<$k2, $k3, $k4>";
  $k1 = $k1+1;
}

# Close output file
close O;

###########################################################
#                   TODO
# 1. Create end cap face
# 2. Calculate Face normals and vertex normals
#    so that smooth triangles can be used
# 3. Generate a complete closed mesh so that it can
#    be used in CSG's
# 4. Add options to aid different sections to be created
# 5. Add options for length, taper, sweep, washout, etc.
# 6. Write in C
# 7. Release under GPL
#
###########################################################