User:Petteri Aimonen/Progressive cavity pump POV-Ray source

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
// Progressive cavity pump animation PovRAY scene description file.
// Released into public domain.
// -- Petteri Aimonen, 2009-10-18

#include "shapes.inc"
#include "transforms.inc"

#declare DefaultTexture  = 
texture {
    pigment { rgb <252/256, 233/256, 79/256> }
    finish {
        phong 1
        crand 0.02
    }
}

#declare RotorTexture =
texture {
    pigment {
        granite
        color_map {
            [0.0 rgb <0.8, 0.8, 0.8>]
            [0.6 rgb <0.4, 0.4, 0.4>]
        }
    }
    finish {
        ambient 0.3
        diffuse 0.7
        reflection 0.15
        brilliance 8
        specular 0.8
        roughness 0.1
    }
    scale <0.5, 1, 10>
}

#declare  PipeTexture  = 
texture {
    pigment { rgb <211/256, 215/256, 207/256> }
    finish {
        metallic
        reflection 0.2
        specular 0.4
    }
}

#declare  ShaftTexture  = 
texture {
    pigment {
        granite
        color_map {
            [0.0 rgb <0.8, 0.8, 0.8>]
            [0.6 rgb <0.4, 0.4, 0.4>]
        }
    }
    
    finish {
        metallic
        reflection 0.2
        specular 0.4
    }
    
    scale <0.5, 1, 10>
}

#declare RubberTexture  = 
texture {
    pigment { rgb <80/256, 80/256, 80/256> }
    finish {
        phong 0.2
        crand 0.02
    }
}

#declare LiquidMaterial =
material {
    texture {
        pigment {
             rgbft <0.8, 0.8, 1.0, 0.9, 0.2>
        }
    }
    interior { ior 1.33 }
}

#declare BubbleMaterial =
material {
    texture {
        pigment {
            rgbft <1, 1, 1, 0.9, 0.2>
        }
    }
    interior {ior 1.00}
}

#declare CavityTexture =
texture {
    pigment { rgb <52/256, 52/256, 240/256> }
    finish {
        phong 0.2
        crand 0.02
    }
}

#declare Rotor =
union {
    Round_Cylinder_Union(<0.06, -0.07, -0.2>, <0.06, -0.07, -0.05>, 0.35, 0.05)
    
    difference {
        Round_Cylinder_Union (
            <0.06, -0.07, -0.4>, <0.06, -0.07, -0.1>, 0.2, 0.05
        )
        cylinder {
            <0.06, -0.07, -0.5>, <0.06, -0.07, -0.2>, 0.15
        }
    }
    
    intersection {
        union {
            cone {
                <0.06, -0.07, -0.1>, 0.35
                <0.06, -0.07, 0.11>, 0.50
            }
            box {
                <-5, -5, 0.1>, <5, 5, 8>
            }
        }
        sphere_sweep {
            // Single helix
            b_spline
            
            #declare Pos=0;
            #declare Turns=4;
            #declare Accuracy=8;
            #declare Length=4;
            #declare Count=Accuracy * Turns;
            Count
            #while (Count > 0)
                <0.1 * sin(Pos * Turns * 2 * pi), 0.1 * cos(Pos * Turns * 2 * pi), Pos * Length>, 0.35
                #declare Pos=Pos + 1/Turns/Accuracy;
                #declare Count=Count - 1;
            #end
            
            translate <0, 0, -0.5>
        }
    }
}

#declare Stator =
difference {
    cylinder {<0, 0, 0.5>, <0, 0, 3.5>, 0.6}
    union {
        // Double helix
        sphere_sweep {
            b_spline
            
            #declare Pos=0;
            #declare Turns=2;
            #declare Accuracy=8;
            #declare Length=4;
            #declare Count=Accuracy * Turns;
            Count
            #while (Count > 0)
                <0.2 * sin(Pos * Turns * 2 * pi), 0.2 * cos(Pos * Turns * 2 * pi), Pos * Length>, 0.3
                #declare Pos=Pos + 1/Turns/Accuracy;
                #declare Count=Count - 1;
            #end
        }
        
        sphere_sweep {
            b_spline
            
            #declare Pos=0;
            #declare Turns=2;
            #declare Accuracy=8;
            #declare Length=4;
            #declare Count=Accuracy * Turns;
            Count
            #while (Count > 0)
                <0.2 * sin(pi + Pos * Turns * 2 * pi), 0.2 * cos(pi + Pos * Turns * 2 * pi), Pos * Length>, 0.3
                #declare Pos=Pos + 1/Turns/Accuracy;
                #declare Count=Count - 1;
            #end
        }
    }
    
    translate <0, 0, -0.5>
}

// The pipe inside which the stator is
#declare StatorPipe =
difference {
    union {
        Round_Cylinder_Union(<0, 0, -2.1>, <0, 0, 4.1>, 0.7, 0.05)
        cylinder {
            <0, 0, 4>, <0, 0, 8>, 0.2
        }
        cylinder {
            <0, 0.65, -1>, <0, 8, -1>, 0.2
        }
    }
    
    union {
        Round_Cylinder_Union(<0, 0, -2>, <0, 0, 4>, 0.6, 0.05)
        cylinder {
            <0, 0, 3>, <0, 0, 9>, 0.15
        }
        
        cylinder {
            <0, 0, -3>, <0, 0, -1>, 0.1
        }
        
        cylinder {
            <0, 0.5, -1>, <0, 8, -1>, 0.15
        }
        
        // Rounded pipe end
        difference {
            cylinder {
                <0, 0, 3.9>, <0, 0, 4.05>, 0.20
            }
            
            torus {
                0.20, 0.05
                rotate <90, 0, 0>
                translate <0, 0, 4.05>
            }
        }
    }
}

// Input shaft
union {
    cylinder {
        <0, 0, -8>, <0, 0, -1.7>, 0.095
    }
    
    difference {
        Round_Cylinder_Union (
            <0, 0, -1.8>, <0, 0, -1.5>, 0.2, 0.05
        )
        cylinder {
            <0, 0, -1.75>, <0, 0, -1>, 0.15
        }
    }
    
    texture {ShaftTexture}
    rotate <0, 0, 360 * clock>
}

// Rotor movement
#declare RotorAngle = 360 * clock;
#declare RotorPoint = <
    0.1 * cos(RotorAngle * pi/180),
    -0.1 * sin(RotorAngle * pi/180), 0>;

// Transfer shaft
union {
    #declare StartPoint = <0, 0, -1.6>;
    #declare EndPoint =
        RotorPoint + vaxis_rotate(<0.06, -0.07, -0.3>, <0, 0, 1>,
        90 + RotorAngle);

    sphere {
        StartPoint, 0.15
    }
    sphere {
        EndPoint, 0.15
    }
    cylinder {
        StartPoint, EndPoint, 0.1
    }
    
    texture {ShaftTexture}
    
    translate -StartPoint
    Axis_Rotate_Trans(EndPoint - StartPoint, 360 * clock)
    translate StartPoint
}

#declare RotatingRotor = 
object {
    Rotor
    
    rotate <0, 0, 90 + RotorAngle>
    // The position rotates in the opposite direction
    translate RotorPoint
}

#declare Cavities =
difference {
    cylinder {
        <0, 0, 0.1>, <0, 0, 2.99>, 0.59
    }
    union {
        object {RotatingRotor}
        object {Stator}
    }
}

object {
    Rotor
    texture {RotorTexture}
    
    rotate <0, 0, 90 + RotorAngle>
    // The position rotates in the opposite direction
    translate RotorPoint
}

#declare StatorCutaway =
box {
    <0, 0, -1.9>, <2, 8, 3.9>
}

difference {
    intersection {
        box {<-5, -5, 0.15>, <5, 5, 8>}
        object { Stator }
    }
    object { StatorCutaway }
    texture {RubberTexture}
}

difference {
    object { StatorPipe }
    object { StatorCutaway }
    texture {PipeTexture}
}

merge {
    cylinder {
        <0, 0, -2.01>, <0, 0, 0.15>, 0.601
    }
    cylinder {
        <0, 0, -1>, <0, 8, -1>, 0.151
    }
    cylinder {
        <0, 0, 2.98>, <0, 0, 4.01>, 0.601
    }
    object {
        Cavities
        translate <0.0001, 0.00001, -0.001>
    }
    material {LiquidMaterial}
}

// Bubbles in input pipe
#declare BubblePath1 =
spline {
    natural_spline
    0, <0, 8, -1>,
    7, <0.05, 1, -1.05>,
    7.4, <0, 0.6, -1.05>,
    9, <-0.4, 0, 0>
}

sphere {
    BubblePath1(clock * 9), 0.05
    material {BubbleMaterial}
}

#declare BubblePath2 =
spline {
    natural_spline
    0, <0, 5, -1>,
    5, <0, 1, -1>,
    5.5, <0.04, 0.5, -1>,
    10, <-0.4, 0, -0.5>
}

sphere {
    BubblePath2(clock * 10), 0.02
    material {BubbleMaterial}
}

// Bubbles in output pipe
#declare BubblePath3 =
spline {
    natural_spline
    0, <-0.5, 0, 3.1>,
    1, <0.3, 0.5, 3.5>,
    2, <0, 0.05, 3.9>,
    5, <0, 0, 8>
}

sphere {
    BubblePath3(clock * 5), 0.02
    material {BubbleMaterial}
}

#declare BubblePath4 =
spline {
    natural_spline
    0, <-0.4, -0.3, 3.1>,
    1, <-0.3, -0.4, 3.5>,
    2, <0, 0, 3.8>,
    5, <0, 0.05, 8>
}

sphere {
    BubblePath4(clock * 5), 0.05
    material {BubbleMaterial}
}

// Bubbles in cavities
#declare BubblePath5 =
spline {
    natural_spline
    0, <0, 0.35, 0.1>,
    1, <0.3, 0.2, 0.7>,
    2, <0.4, 0, 1.2>
    3, <0.3, -0.3, 1.2>
}

sphere {
    BubblePath5(clock * 3), 0.05
    material {BubbleMaterial}
}

#declare BubblePath6 =
spline {
    natural_spline
    0, <0, 0.45, 1.2>,
    1, <0.3, 0.35, 1.6>,
    2, <0.4, 0, 2>
    3, <0.3, -0.3, 2>
}

sphere {
    BubblePath6(clock * 3), 0.02
    material {BubbleMaterial}
    scale <0.8, 0.8, 1.2>
}

#declare BubblePath7 =
spline {
    natural_spline
    0, <-0.15, 0.25, 2.0>,
    1, <0.1, 0.3, 2.4>,
    1.5, <0.15, 0.25, 2.6>
    2.2, <0.3, 0, 3.2>
    3, <0.4, -0.3, 3.2>
}

sphere {
    BubblePath7(clock * 3), 0.05
    material {BubbleMaterial}
}

object {
    Cavities
    texture {CavityTexture}
    translate <0, 1.5, 0>
}

background { rgb <1, 1, 1> }

camera {
    right x*16/9
    location <4, 2.3, 1>
//    location <0, 0, 6>
    look_at <2, 1.3, 1>
//    location <3, 2, -1.5>
//    look_at <0, 0, -1.5>
}

light_source {
    <3, 2, 2>
    color rgb <1, 1, 1>
    shadowless
//     area_light
//     <0, 0, 1> <0, 1, 0> 4 4
//     adaptive 2
//     fade_power 2
//     fade_distance 3
}

light_source {
    <2, 6, 0>
    color rgb <1, 1, 1>
    shadowless
}