Example #1
0
class TransmissionDemo(object):
    def __init__(self, theta=0.0, phi=0.0, etaIn=1.0, etaOut=1.0):
        self.etaIn = etaIn
        self.etaOut = etaOut
        
        self.incoming = SphericalCoords(theta * math.pi, phi * 2 * math.pi)
        self.reflected = self.incoming.reflect()
        self.refracted = self.incoming.refract(etaIn, etaOut)

        self.initScene()
        
    def update(self, theta=None, phi=None, etaIn=None, etaOut=None):
        if theta != None:
            self.incoming.theta = theta * math.pi
        if phi != None:
            self.incoming.phi = phi * 2 * math.pi
        if etaIn != None:
            self.etaIn = (abs(etaIn) > 0) and etaIn or sys.float_info.epsilon
        if etaOut != None:
            self.etaOut = (abs(etaOut) > 0) and etaOut or sys.float_info.epsilon
        self.reflected = self.incoming.reflect()
        self.refracted = self.incoming.refract(self.etaIn, self.etaOut)

        # set incoming arrow so that it point towards the transmission point
        incomingDir = vector(self.incoming.toCartesian())
        self.incomingArrow.pos = incomingDir
        self.incomingArrow.axis = -vector(incomingDir)
        
        self.reflectedArrow.axis = self.reflected.toCartesian()
        
        self.refractedArrow.axis = self.refracted.toCartesian()

    def initScene(self):
        w = 500
        display(x=w, y=0, width=w, height=w, range=1.5, forward=-vector(0,1,1), newzoom=1)
        self.controls = controls(0, 0, width=w, height=w)
        self.incomingThetaSlider = slider(pos=(-10,-50), width=7, length=100, axis=(0,1,0),
            action=lambda: self.update(theta=(self.incomingThetaSlider.value / 100.0)-0.5))
        self.incomingPhiSlider = slider(pos=(10,-50), width=7, length=100, axis=(0,1,0),
            action=lambda: self.update(phi=self.incomingPhiSlider.value / 100.0))
        self.etaInSlider = slider(pos=(50,-50), width=7, length=100, axis=(0,1,0),
            action=lambda: self.update(etaIn=(self.etaInSlider.value / 100.0)))

        drawWorldCoordinates()
        box(pos=(0,0,0), axis=(0,0,1), length=0.01, height=1.0, width=1.0, opacity=0.25)
        box(pos=(0,0,-0.5), axis=(0,0,1), length=1, height=1.0, width=1.0, opacity=0.1)

        self.incomingArrow = drawRayDirection()
        self.reflectedArrow = drawRayDirection(color=visual.color.green)
        self.refractedArrow = drawRayDirection(color=visual.color.orange)

        self.incomingThetaSlider.value = 100.0 * ((self.incoming.theta / math.pi) + 0.5)
        self.incomingPhiSlider.value = 100.0 * self.incoming.phi / (2 * math.pi)
        self.etaInSlider.value = 100.0 * self.etaIn

    def run(self):
        while True:
            rate(100)
            self.controls.interact() # check for events, drive actions; must be executed repeatedly in a loop
def visualizeSphereParametrization():
    sphere(radius=1, opacity=0.25, material=materials.show_mat_pos)
    thetaSampleCount = 20
    phiSampleCount = 40
    thetaStep = 1.0 / float(thetaSampleCount)
    phiStep = 1.0 / float(phiSampleCount)
    for i in range(0, thetaSampleCount + 1):
        for j in range(0, phiSampleCount + 1):
            spherical = SphericalCoords(
                theta = (i * thetaStep - 0.5) * math.pi,
                phi = (j * phiStep) * 2 * math.pi)
            color = visual.color.hsv_to_rgb((j * phiStep, i * thetaStep, 1.0))
            points(pos=[spherical.toCartesian()], color=color)
Example #3
0
class TransmissionDemo(object):
    def __init__(self, theta=0.0, phi=0.0, etaIn=1.0, etaOut=1.0):
        self.etaIn = etaIn
        self.etaOut = etaOut

        self.incoming = SphericalCoords(theta * math.pi, phi * 2 * math.pi)
        self.reflected = self.incoming.reflect()
        self.refracted = self.incoming.refract(etaIn, etaOut)

        self.initScene()

    def update(self, theta=None, phi=None, etaIn=None, etaOut=None):
        if theta != None:
            self.incoming.theta = theta * math.pi
        if phi != None:
            self.incoming.phi = phi * 2 * math.pi
        if etaIn != None:
            self.etaIn = (abs(etaIn) > 0) and etaIn or sys.float_info.epsilon
        if etaOut != None:
            self.etaOut = (abs(etaOut) >
                           0) and etaOut or sys.float_info.epsilon
        self.reflected = self.incoming.reflect()
        self.refracted = self.incoming.refract(self.etaIn, self.etaOut)

        # set incoming arrow so that it point towards the transmission point
        incomingDir = vector(self.incoming.toCartesian())
        self.incomingArrow.pos = incomingDir
        self.incomingArrow.axis = -vector(incomingDir)

        self.reflectedArrow.axis = self.reflected.toCartesian()

        self.refractedArrow.axis = self.refracted.toCartesian()

    def initScene(self):
        w = 500
        display(x=w,
                y=0,
                width=w,
                height=w,
                range=1.5,
                forward=-vector(0, 1, 1),
                newzoom=1)
        self.controls = controls(0, 0, width=w, height=w)
        self.incomingThetaSlider = slider(
            pos=(-10, -50),
            width=7,
            length=100,
            axis=(0, 1, 0),
            action=lambda: self.update(theta=(self.incomingThetaSlider.value /
                                              100.0) - 0.5))
        self.incomingPhiSlider = slider(
            pos=(10, -50),
            width=7,
            length=100,
            axis=(0, 1, 0),
            action=lambda: self.update(phi=self.incomingPhiSlider.value / 100.0
                                       ))
        self.etaInSlider = slider(
            pos=(50, -50),
            width=7,
            length=100,
            axis=(0, 1, 0),
            action=lambda: self.update(etaIn=(self.etaInSlider.value / 100.0)))

        drawWorldCoordinates()
        box(pos=(0, 0, 0),
            axis=(0, 0, 1),
            length=0.01,
            height=1.0,
            width=1.0,
            opacity=0.25)
        box(pos=(0, 0, -0.5),
            axis=(0, 0, 1),
            length=1,
            height=1.0,
            width=1.0,
            opacity=0.1)

        self.incomingArrow = drawRayDirection()
        self.reflectedArrow = drawRayDirection(color=visual.color.green)
        self.refractedArrow = drawRayDirection(color=visual.color.orange)

        self.incomingThetaSlider.value = 100.0 * (
            (self.incoming.theta / math.pi) + 0.5)
        self.incomingPhiSlider.value = 100.0 * self.incoming.phi / (2 *
                                                                    math.pi)
        self.etaInSlider.value = 100.0 * self.etaIn

    def run(self):
        while True:
            rate(100)
            self.controls.interact(
            )  # check for events, drive actions; must be executed repeatedly in a loop