
# r numbers taken from 
# http://sandypointboatworks.com/boatstore/image/data/boat_plans/Runabout%20Plans/Whitecap/whitecap-building-plans-study-sheet.jpg

# rib*.fig taken by tracing around rib plans in that same jpeg.
# then duplicated and trimmed, a is top(hull sides), b is bottom (hull planing surface)
echo "# upper ribs" > delme.txt

gawk 'BEGIN { r[1]=22.5; r[2]=22; r[3]=25; r[4]=25; r[5]=25; r[6]=19.5; r[7]=19.5; r[8]=19.5; r[9]=25; r[10]=23; r[11]=23; r[12]=23; r[13]=30; 
} /^#FIG/ { p=0; rib++; x+=r[rib]; printf "#rib %d\n",rib; } {
   if(p==1)
    {
      for(i=1;i<=NF;i+=2)
       {
         y=11976-$i;  # beam, constant extracted from rib1baseline.fig
         if(rib<9);
         else
            y=-y;
         z=12467-$(i+1);    # height
         y/=45; z/=45;  # xfig internal units to xfig mm

         y/=5.1428;  # scale xfig mm to inches as used in plan (to also scale to the rib spacing r[])
         z/=5.1428; 
         # there was another ratio - 5.514, derived from the plan using boat length. Which is it??

         y*=36/30;   # beam width is supposed to be 72", not 60"

         printf "%f %f %f\n",x,y,z;
         #printf "%f %f %f\n",x,-y,z;
       }
     }
 }  /^2 1 / {p=1;}' rib{1,2,3,4,5,6,7,8,9,10,11,12,13}a.fig >> delme.txt

# x is along the length (inches)
# y is along the beam (inches)
# and z is height (inches)

# all a tad tatty scaling, sizes make sense but wouldn't want to go back to it.

echo "# lower ribs" >> delme.txt

gawk 'BEGIN { r[1]=22.5; r[2]=22; r[3]=25; r[4]=25; r[5]=25; r[6]=19.5; r[7]=19.5; r[8]=19.5; r[9]=25; r[10]=23; r[11]=23; r[12]=23; r[13]=30; 
} /^#FIG/ { p=0; rib++; x+=r[rib]; printf "#rib %d\n",rib; } {
   if(p==1)
    {
      for(i=1;i<=NF;i+=2)
       {
         y=11976-$i;  # beam
         if(rib<9);
         else
            y=-y;
         z=12467-$(i+1);   # height
         y/=45; z/=45;  # xfig internal units to xfig mm

         y/=5.1428;  # scale xfig mm to inches as used in plan (to also scale to the rib spacing r[])
         z/=5.1428;

         y*=36/30;   # beam width is supposed to be 72", not 60"

         printf "%f %f %f\n",x,y,z;
         #printf "%f %f %f\n",x,-y,z;
       }
     }
 }  /^2 1 / {p=1;}' rib{1,2,3,4,5,6,7,8,9,10,11,12,13}b.fig >> delme.txt

echo "# keel" >> delme.txt

# keel line, from bow to stern..  keelline.fig also has box marking the base line to the keel line.
gawk 'BEGIN { baseliney=1234;   baselinex=0;
} /^#FIG/ { p=0; } /^[^	]/ {p=0;} {
   if(p==1)
    {
      for(i=1;i<=NF;i+=2)
       {
         y=$i-6308;  # length
         z=23392-$(i+1);  # height, from base line. number extracted from keelline.fig
         y/=45; z/=45;  # xfig internal units to xfig mm

         y/=1.836;  # scale xfig mm to the 302 " it should be
         z/=5.514;   # " but based on boat beam.
         z*=2.28;

         printf "%f %f %f\n",y,0,z;
       }
     }
 }  /^2 1 / {p=1;}' keelline.fig >> delme.txt

# 2 1 


echo "# shaft" >> delme.txt

# shaft line, from bow to stern..  shaftline.fig also has box marking the base line to the keel line.
gawk 'BEGIN { baseliney=1234;   baselinex=0;
} /^#FIG/ { p=0; } /^[^	]/ {p=0;} {
   if(p==1)  # straight shaft line, used to feed coords into openscad
    {
      printf "# shaft\n";
      for(i=1;i<=NF;i+=2)
       {
         y=$i-6308;  # length
         z=23392-$(i+1);  # height, from base line. number extracted from keelline.fig
         y/=45; z/=45;  # xfig internal units to xfig mm

         y/=1.836;  # scale xfig mm to the 302 " it should be
         z/=5.514;   # " but based on boat beam.
         z*=2.28;

         printf "%f %f %f\n",y,0,z;
         p=0;
       }
     }
    if(p==2)  # shaft block, near prop. need these in precise order to draw 3D elipses around
     {
       printf "# block\n";
       for(i=1;i<=NF;i+=2)
        {
          y=$i-6308;  # length
          z=23392-$(i+1);  # height, from base line. number extracted from keelline.fig
          y/=45; z/=45;  # xfig internal units to xfig mm

          y/=1.836;  # scale xfig mm to the 302 " it should be
          z/=5.514;  # " but based on boat beam.
          z*=2.28;

          printf "%f %f %f\n",y,0,z;
          p=0;

        }
     }
 }  /^2 1 / {p=1;}  /^2 3 / {p=2;}' shaftline.fig >> delme.txt

