Ejemplo n.º 1
0
 def getFaceNormal(self, face):
     points = []
     for v in face:
         points.append(Point(v[0], v[1], v[2]))
     vecA = Vector.from_points(points[0], points[1])
     vecB = Vector.from_points(points[0], points[2])
     vecResult = Vector.cross(vecA, vecB)
     return vecResult
Ejemplo n.º 2
0
def getUVFaceNormal( facepath ):
	uvs = getWindingOrder(facepath)

	if len(uvs) < 3: return (1,0,0) #if there are less than 3 uvs we have no uv area so bail

	#get edge vectors and cross them to get the uv face normal
	uvAPos = cmd.polyEditUV(uvs[0], query=True, uValue=True, vValue=True)
	uvBPos = cmd.polyEditUV(uvs[1], query=True, uValue=True, vValue=True)
	uvCPos = cmd.polyEditUV(uvs[2], query=True, uValue=True, vValue=True)
	uvAB = Vector( [uvBPos[0]-uvAPos[0], uvBPos[1]-uvAPos[1], 0] )
	uvBC = Vector( [uvCPos[0]-uvBPos[0], uvCPos[1]-uvBPos[1], 0] )
	uvNormal = uvAB.cross( uvBC ).normalize()

	return uvNormal
Ejemplo n.º 3
0
def getUVFaceNormal( facepath ):
	uvs = getWindingOrder(facepath)

	if len(uvs) < 3: return (1,0,0) #if there are less than 3 uvs we have no uv area so bail

	#get edge vectors and cross them to get the uv face normal
	uvAPos = cmd.polyEditUV(uvs[0], query=True, uValue=True, vValue=True)
	uvBPos = cmd.polyEditUV(uvs[1], query=True, uValue=True, vValue=True)
	uvCPos = cmd.polyEditUV(uvs[2], query=True, uValue=True, vValue=True)
	uvAB = Vector( [uvBPos[0]-uvAPos[0], uvBPos[1]-uvAPos[1], 0] )
	uvBC = Vector( [uvCPos[0]-uvBPos[0], uvCPos[1]-uvBPos[1], 0] )
	uvNormal = uvAB.cross( uvBC ).normalize()

	return uvNormal
Ejemplo n.º 4
0
    def add_slab_vectorial(self, n1, thickness, alpha):
        """ 
        Calculates the effect of the slab, using vectorial theory, considering s and p polarizations.
        n1: refractive index of the slab
        thickness: thickness
        alpha: angle from the xy plane, conventionally from the y axis 
        """

        n0 = self.n
        k = self.k
        k1 = n1 / n0 * k

        kx = self.kx
        ky = self.ky
        kz = self.kz

        # k vector
        vk = Vector(kx, ky, kz)
        uk = vk.norm

        ux = Vector(1, 0, 0).to_size_like(vk)
        uy = Vector(0, 1, 0).to_size_like(vk)
        uz = Vector(0, 0, 1).to_size_like(vk)

        # normal to the surface
        u = Vector(0, np.sin(alpha), np.cos(alpha)).to_size_like(vk)
        us = (uk.cross(u)).norm
        up = us.cross(uk)

        E0 = ux  # assume initial polarization along x

        E = uk.cross(-uz.cross(E0))
        E = E / E.mag

        Es = E.dot(us)
        Ep = E.dot(up)

        print(E)

        # incidence angle, relative to the slab surface
        #phi0 = np.arccos(uk.cross(u).mag())
        phi0 = np.arcsin(np.abs(uk.dot(u)))

        #Snell's law:
        phi1 = np.arcsin(n0 / n1 * np.sin(phi0))

        beta = phi0 - phi1

        #uk1 = uk * np.cos(beta) - up * np.sin(beta)

        with np.errstate(invalid='ignore'):
            theta0 = np.arcsin(ky / k)
            theta1 = np.arcsin(n0 / n1 * np.sin(theta0 + alpha)) - alpha
            ky1 = k1 * np.sin(theta1)
            k_rho1 = np.sqrt(kx**2 + ky1**2)
            kz1 = np.sqrt(k1**2 - k_rho1**2)

        # additional phase due to propagation in the slab
        phase = (kz1 - kz) * 2 * np.pi * thickness / np.cos(alpha)

        # Fresnel law of refraction
        Ts01 = 2 * n0 * np.cos(theta0) / (n0 * np.cos(theta0) +
                                          n1 * np.cos(theta1))
        Tp01 = 2 * n0 * np.cos(theta0) / (n0 * np.cos(theta1) +
                                          n1 * np.cos(theta0))
        Ts10 = 2 * n1 * np.cos(theta1) / (n1 * np.cos(theta1) +
                                          n0 * np.cos(theta0))
        Tp10 = 2 * n1 * np.cos(theta1) / (n1 * np.cos(theta0) +
                                          n0 * np.cos(theta1))
        transmittance = (Es * Ts01 * Ts10 + Ep * Tp01 * Tp10
                         )  # assuming equal s and p polarization components

        #bprint(transmittance)
        self.amplitude *= transmittance

        self.phase += phase
        self.thickness = thickness
        self.alpha = alpha
        self.n1 = n1
        self.correct_slab_defocus()
Ejemplo n.º 5
0
import numpy as np
from vectors import Point, Vector
import functools

v1 = Vector(1, 2, 3)
v2 = Vector(10, 20, 30)
print(v1.add(10))
print(v1.sum(v2))  # displays <1 22 33>

print(v1.magnitude())

#We can multiply a vector by a real number.

print(v2.multiply(4))  #=> Vector(4.0, 8.0, 12.0)
print(v1.dot(v2))
print(v1.dot(v2, 180))
print(v1.cross(v2))

print(v1.angle(v2))

print(v1.parallel(v2))
print(v1.perpendicular(v2))
#print(v1.non_parallel(v2))