User:Petteri Aimonen/Cycloidal drive POV-Ray source

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

This is the POV-Ray source code for Image:Cycloidal_drive.gif

// POV-Ray scene description file illustrating cycloidal drive mechanism
// Released into public domain
// Author: Petteri Aimonen <jpa at wp.mail.kapsi.fi>
// Date: 2009-09-04

// Colors are from tango palette
#declare CycloidalDiscTexture  = 
texture {
    pigment { rgb <252/256, 233/256, 79/256> }
    finish {
        phong 1
        crand 0.02
    }
}

#declare InputShaftTexture  = 
texture {
    pigment { rgb <138/256, 226/256, 52/256> }
    finish {
        phong 1
        crand 0.02
    }
}

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

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

#declare RingPinHilight =
texture {
    pigment { rgb <211/256, 215/256, 207/256> }
    finish {
        metallic
        ambient 0.3
        reflection 0.2
        specular 0.4
        crand 0.02
    }
}

#declare OutputShaftTexture  = 
texture {
    pigment { rgb <173/256, 127/256, 168/256> }
    finish {
        phong 1
        crand 0.02
    }
}

#declare OutputShaftHilight =
texture {
    pigment { rgb <173/256, 127/256, 168/256> }
    finish {
        ambient 0.5
        phong 1
        crand 0.02
    }
}

#declare ForceArrowTexture  = 
texture {
    pigment { rgb <204/256, 0, 0> }
    finish {
        ambient 0.5
    }
}


#declare cycloidal_gear = prism {
    linear_sweep
    bezier_spline
    1.0, //top
    0.0, //bottom
    92 //nr points
    /*   0*/ <0.91986006, 0.00008262>, <1.05633970, -0.04911738>, <1.00699980, -0.29861738>, <0.85846022, -0.28431738>,
    /*   1*/ <0.85846022, -0.28431738>, <0.74852051, -0.29881738>, <0.68707067, -0.43801738>, <0.73473055, -0.53321738>,
    /*   2*/ <0.73473055, -0.53321738>, <0.80570036, -0.59671738>, <0.73852054, -0.72641738>, <0.65751075, -0.75251738>,
    /*   3*/ <0.65751075, -0.75251738>, <0.55982101, -0.79711738>, <0.48186122, -0.66981738>, <0.38247148, -0.73421738>,
    /*   4*/ <0.38247148, -0.73421738>, <0.26674179, -0.76971738>, <0.31260167, -0.90921738>, <0.23023189, -0.96911738>,
    /*   5*/ <0.23023189, -0.96911738>, <0.16231207, -1.02221738>, <0.02841242, -1.00771738>, <0.00028250, -0.91911738>,
    /*   6*/ <0.00028250, -0.91911738>, <-0.02942742, -0.81971738>, <-0.17825703, -0.78441738>, <-0.25805682, -0.84681738>,
    /*   7*/ <-0.25805682, -0.84681738>, <-0.30447669, -0.92481738>, <-0.41216641, -0.94201738>, <-0.48237622, -0.88441738>,
    /*   8*/ <-0.48237622, -0.88441738>, <-0.60264590, -0.82241738>, <-0.48541621, -0.68451738>, <-0.56975599, -0.60401738>,
    /*   9*/ <-0.56975599, -0.60401738>, <-0.63347582, -0.49721738>, <-0.74936551, -0.56511738>, <-0.83542528, -0.52751738>,
    /*  10*/ <-0.83542528, -0.52751738>, <-0.92743504, -0.47841738>, <-0.95547497, -0.32471738>, <-0.85558523, -0.27001738>,
    /*  11*/ <-0.85558523, -0.27001738>, <-0.77441545, -0.18171738>, <-0.82229532, -0.01461738>, <-0.94107500, 0.00838262>,
    /*  12*/ <-0.94107500, 0.00838262>, <-1.04030470, 0.07788262>, <-1.00804480, 0.25618262>, <-0.89040514, 0.28428262>,
    /*  13*/ <-0.89040514, 0.28428262>, <-0.75618549, 0.26848262>, <-0.66210574, 0.45858262>, <-0.75412550, 0.55718262>,
    /*  14*/ <-0.75412550, 0.55718262>, <-0.80467537, 0.67378262>, <-0.64705578, 0.81658262>, <-0.54021607, 0.74408262>,
    /*  15*/ <-0.54021607, 0.74408262>, <-0.44172633, 0.66798262>, <-0.26757679, 0.76638262>, <-0.28309675, 0.89148262>,
    /*  16*/ <-0.28309675, 0.89148262>, <-0.25807682, 1.01858262>, <-0.03613741, 1.04448262>, <0.00136249, 0.91318262>,
    /*  17*/ <0.00136249, 0.91318262>, <0.04490238, 0.79988262>, <0.23046189, 0.77928262>, <0.29159172, 0.88558262>,
    /*  18*/ <0.29159172, 0.88558262>, <0.38564147, 0.97218262>, <0.56295100, 0.88068262>, <0.54494105, 0.75348262>,
    /*  19*/ <0.54494105, 0.75348262>, <0.49319119, 0.63818262>, <0.63526081, 0.49318262>, <0.75208050, 0.54398262>,
    /*  20*/ <0.75208050, 0.54398262>, <0.88233016, 0.56718262>, <0.97447991, 0.37678262>, <0.88217016, 0.28758262>,
    /*  21*/ <0.88217016, 0.28758262>, <0.79549039, 0.24248262>, <0.80244037, 0.10848262>, <0.85777022, 0.04018262>,
    /*  22*/ <0.85777022, 0.04018262>, <0.87411018, 0.02148262>, <0.89557012, 0.00628262>, <0.91986006, 0.00008262>
}

#declare cycloidal_disc =
difference {
    object {
        cycloidal_gear
        scale <1, 0.1, 1>
    }

    union {
        // Eccentric bearing hole
        cylinder {
            <0, -0.1, 0>, <0, 0.3, 0>, 0.4
        }
    
        // Output shaft roller holes
        #declare Count=10;
        #while (Count > 0)
            cylinder {
                <0.6, -0.1, 0>, <0.6, 0.3, 0>, 0.15
                rotate <0, 36 * Count - 8, 0>
            }
            #declare Count=Count - 1;
        #end
    }
}

#declare ball_bearing =
union {
    // Inner ring
    difference {
        cylinder {
            <0, 0, 0>, <0, 0.2, 0>, 0.70
        }
        cylinder {
            <0, -0.1, 0>, <0, 0.21, 0>, 0.60
        }
    }
    
    // Outer ring
    difference {
        cylinder {
            <0, 0, 0>, <0, 0.2, 0>, 1
        }
        cylinder {
            <0, -0.1, 0>, <0, 1, 0>, 0.90
        }
    }
    
    // Balls
    union {
        #declare Count=24;
        #while (Count > 0)
            sphere {
                <0.8, 0.1, 0>, 0.1
                rotate <0, 360 / 24 * Count, 0>
            }
            #declare Count=Count-1;
        #end
        rotate <0, (360 - 36) * clock, 0>
    }
}

#declare cycloidal_disc_assembly=
union {
    union {
        object {
            cycloidal_disc
            texture {CycloidalDiscTexture}
        }
        
        object {
            ball_bearing
            scale <0.4, 0.4, 0.4>
            texture {BallBearingTexture}
            translate <0, 0.01, 0>
        }
        
        rotate <0, (-360 - 36) * clock - 15.3, 0>
    }

    // Input shaft
    cylinder {
        <0.09, 0, 0>, <0.09, 1, 0>, 0.1
        texture {InputShaftTexture}
    }
    
    // Something to hold input shaft inside bearing
    cylinder {
        <0, 0, 0>, <0, 0.08, 0>, 0.4 * 0.6
        texture {InputShaftTexture}
    }
    
    // Position indicator
    box {
        <0.09, 0.1, -0.02>, <-0.015, 1.01, 0.02>
        pigment { rgb <78 / 256, 154 / 256, 6 / 256> }
    }
    box {
        <0.09, 0.1, -0.02>, <-0.4 * 0.6, 0.085, 0.02>
        pigment { rgb <78 / 256, 154 / 256, 6 / 256> }
    }
    
    translate <-0.09, 0, 0>
    rotate <0, 360 * clock, 0>
}

#declare ring_pins =
union
{
    #declare Count=11;
    #while (Count > 0)
        intersection {
            cylinder {
                <0, 0, 0>, <0, 0.2, 0>, 0.091*2
            }
            box {
                <-1, -0.1, 0>, <1, 1.1, 1>
            }
            
            translate <0, 0, -1 - 0.091*2 + 0.02>
            rotate <0, 360 / 11 * Count, 0>
            
//             #if (mod(Count + 11 - 3, 11) = floor(clock * 11 + 0.3))
//             texture {RingPinHilight}
//             #else
            texture {RingPinTexture}
//             #end
            
            #declare Count = Count - 1;
        }
    #end
}

#declare output_shaft_assembly =
union {
    // Base plate
    cylinder {
        <0, 0, 0>, <0, 0.1, 0>, 0.8
        texture {OutputShaftTexture}
    }
    
    #declare Count=10;
    #while (Count > 0)
        // Output roller pins
        cylinder {
            <0.6, 0, 0>, <0.6, 0.4, 0>, 0.15 - 0.091
            rotate <0, 36 * Count - 7, 0>
            
//             #if (mod(Count + 2, 10) = mod(floor(clock * 11 + 0.3), 10))
//             texture {OutputShaftHilight}
//             #else
            texture {OutputShaftTexture}
//             #end
        }
        
        // Position indicators
        box {
            <0, 0.1, -0.01>, <0.105, -1.55, 0.01>
            rotate <0, 36 * Count, 0>
            pigment { rgb <92 / 256, 53 / 256, 102 / 256> }
        }
        
        #declare Count = Count - 1;
    #end

    // Output shaft
    cylinder {
        <0, 0.1, 0>, <0, -1.5, 0>, 0.1
        texture {OutputShaftTexture}
    }

    rotate <0, -36 * clock - 16, 0>
}

object {
    output_shaft_assembly
    translate <0, -0.2, 0>
}

object {
    cycloidal_disc_assembly
}

object {
    ring_pins
}

background { rgb <1, 1, 1> }

camera {
    location <2, 1, 0>
//    location <0, 3, 0>
    look_at <0, 0, 0>
}

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

light_source {
    <8, 5, -8>
    color rgb <1, 1, 1>
    shadowless
}