POV-Ray : Newsgroups : povray.text.scene-files : Source code for "... Vase from lathes and prisms" Server Time
31 Oct 2024 10:20:04 EDT (-0400)
  Source code for "... Vase from lathes and prisms" (Message 1 to 1 of 1)  
From: Tor Olav Kristensen
Subject: Source code for "... Vase from lathes and prisms"
Date: 12 Sep 2000 19:21:16
Message: <39BEB918.80B0687D@online.no>
Below is the source code for an image I posted 12. Sept. to the
povray.binaries.images news group;
"For Todd Taylor (Vase from lathes and prisms)":
(news://news.povray.org/39BD872A.9D0EE76%40online.no)

which I posted with my reply 12. Sept.:
(news://news.povray.org/39BD88B9.A8295B7D%40online.no)

to his thread in povray.newusers 10. Sept.:
"Can this be done? :) sor-lathe type question":
(news://news.povray.org/39bb051a%241%40news.povray.org)


Note that the "Vase" generated below has a hole in the bottom.

If anyone needs a vase without a bottom hole, then please tell.
(I think I can fix this problem.)


Tor Olav

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2000 by Tor Olav Kristensen
// mailto:tor### [at] hotmailcom
// http://www.crosswinds.net/~tok/tokrays.html
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.1;
#include "colors.inc"

global_settings { ambient_light 3 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Macro used to tilt the area light source

#macro Tilt(Thing, Vector)

  #local xAngle = (Vector.z < 0 ? -1 : 1)*
                  degrees(acos(vnormalize((x + z)*Vector).x));
  #local yAngle = degrees(acos(vnormalize(Vector).y));

  object {
    Thing
    rotate  xAngle*y
    rotate -yAngle*z
    rotate -xAngle*y
  }

#end // macro Tilt

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Some macros to generate lathes from arrays of 2D-points

#macro InsertPoints(PointArray)

  #local NrOfPoints = dimension_size(PointArray, 1);
  #local PtCnt = 0;

  #while (PtCnt < NrOfPoints)
    PointArray[PtCnt],
    #local PtCnt = PtCnt + 1;
  #end // while

#end // macro InsertPoints


#macro LinearLathe(PointArray)

  lathe {
    linear_spline
    dimension_size(PointArray, 1) + 1,
    InsertPoints(PointArray)
    PointArray[0]
  }

#end // macro LinearLathe


#macro QuadraticLathe(PointArray)

  lathe {
    quadratic_spline
    dimension_size(PointArray, 1) + 2,
    InsertPoints(PointArray)
    PointArray[0],
    PointArray[1]
  }

#end // macro QuadraticLathe


#macro CubicLathe(PointArray)

  lathe {
    cubic_spline
    dimension_size(PointArray, 1) + 3,
    InsertPoints(PointArray)
    PointArray[0],
    PointArray[1],
    PointArray[2]
  }

#end // macro CubicLathe


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Some macros to generate prisms from arrays of 2D-points

#macro LinearPrism(PointArray, Y1, Y2)

  prism {
    linear_spline
    Y1, Y2
    dimension_size(PointArray, 1) + 1,
    InsertPoints(PointArray)
    PointArray[0]
  }

#end // macro LinearPrism


#macro QuadraticPrism(PointArray, Y1, Y2)

  prism {
    quadratic_spline
    Y1, Y2
    dimension_size(PointArray, 1) + 2,
    InsertPoints(PointArray)
    PointArray[0],
    PointArray[1]
  }

#end // macro QuadraticPrism


#macro CubicPrism(PointArray, Y1, Y2)

  prism {
    cubic_spline
    Y1, Y2
    dimension_size(PointArray, 1) + 3,
    InsertPoints(PointArray)
    PointArray[0],
    PointArray[1],
    PointArray[2]
  }

#end // macro CubicPrism

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The macro that merges several lathes and prisms in a circle

#macro LathePrism(PointArray, Radius, NrOfSegments, SS, SplineType)

  #local NrOfPts = dimension_size(PointArray, 1);
  #local DegFullStep = 360/NrOfSegments;
  #local RadHalfStep = pi/NrOfSegments;
  #local HH = Radius/cos(RadHalfStep);
  #local LL = Radius*tan(RadHalfStep)*(1 - SS);
  #local PPts = array[NrOfPts]
  #local LPts = array[NrOfPts]
  #local Cnt = 0;
  #while (Cnt < NrOfPts)
    #local PPts[Cnt] = PointArray[Cnt] +    Radius*u;
    #local LPts[Cnt] = PointArray[Cnt] + SS*Radius*u;
    #local Cnt = Cnt + 1;
  #end // while
  #local Cnt = 0;
  #while (Cnt < NrOfSegments)
    object {
      #switch (SplineType)
        #case (1)
          LinearPrism(PPts, -LL, LL)
          #break
        #case (2)
          QuadraticPrism(PPts, -LL, LL)
          #break
        #case (3)
          CubicPrism(PPts, -LL, LL)
          #break
        #else
          #debug "\nMacro LathePrism: Wrong spline type given.\n"
      #end // switch
      rotate -90*x
      rotate Cnt*DegFullStep*y
    }
    intersection {
      plane { -z, 0 }
      plane {  z, 0 rotate -DegFullStep*y }
      object {
        #switch (SplineType)
          #case (1)
            LinearLathe(LPts)
            #break
          #case (2)
            QuadraticLathe(LPts)
            #break
          #case (3)
            CubicLathe(LPts)
            #break
          #else
            #debug "\nMacro LathePrism: Wrong spline type given.\n"
        #end // switch
      }
      translate Radius*(1 - SS)*x + LL*z
      rotate Cnt*DegFullStep*y
    }
    #local Cnt = Cnt + 1;
  #end // while

#end // macro LathePrism

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Initialize som variables and call the macros

// Define the shape of the "Vase". Note that all the first co-
// ordinates for the points below must be positive.
// (And do not add extra values to the first co-ordinates here
// to get a greater "general turning radius". Increase the
// SortOfRadius variable instead.)
#declare VasePoints =
array[27] {
  < 1.5,  0.7>,
  < 2.7,  0.8>,
  < 5.5,  1.8>,
  < 6.7,  3.6>,
  < 6.7,  7.3>,
  < 5.6, 12.3>,
  < 4.5, 16.2>,
  < 4.5, 18.8>,
  < 5.0, 21.3>,
  < 6.0, 24.0>,
  < 7.5, 25.7>,
  < 8.5, 26.4>,
  < 8.6, 27.0>,
  < 7.8, 27.1>,
  < 6.8, 26.6>,
  < 5.2, 24.9>,
  < 4.2, 22.8>,
  < 3.6, 20.5>,
  < 3.4, 18.3>,
  < 3.7, 14.7>,
  < 4.3, 12.3>,
  < 5.5,  7.1>,
  < 5.8,  4.6>,
  < 4.8,  2.8>,
  < 2.6,  2.0>,
  < 1.2,  1.8>,
  < 0.8,  1.2>
}


// I wanted to make the shape 10% higher. And instead
// of altering all the Y co-ordinates, I included the 5
// lines below. (They are of coarse normally not needed.)
#declare Cnt = 0;
#while (Cnt < dimension_size(VasePoints, 1))
  #declare VasePoints[Cnt] = VasePoints[Cnt]*<1.0, 1.1>;
  #declare Cnt = Cnt + 1;
#end // while


// Chose how many "edges" to have
#declare NumberOfSegments = 5;


// Chose the radius at the "narrowest". Note that the hole in the
// bottom will increase with the value chosen below.
#declare SortOfRadius = 5;


// Chose a value greater than 0 and less than 1 for the variable below
// Watch the hole in the bottom while trying different values here.
#declare Roundness = 0.2;


// Chose 1 to use a linear spline, 2 to use a quadratic spline or
// 3 for a cubic spline
#declare TypeOfSpline = 3;


// Use merge instead of union below if you use a "transparent"
// texture and interior
union {
  LathePrism(VasePoints, SortOfRadius, NumberOfSegments,
             Roundness, TypeOfSpline)
//  rotate 180*x   // Uncomment to see the
//  translate 35*y // hole in the bottom
  translate -15*y + 8*x
  pigment { color Red }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

plane { y, -14.5 pigment { color White } }

#declare AreaLight =
light_source {
  100*y
  color White
  area_light 10*x, 10*z, 3, 3
  adaptive 2
  jitter
}

Tilt(AreaLight, <10, 13, -7>)

camera {
 location <0, 30, -40>*1.1
 look_at <0, 2, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.