Ejemplo n.º 1
0
def calculate(R, v, time_step, n_steps):
    # G = 1
    # M1 = 1
    # M2 = 1
    v_low = v / np.sqrt(2)
    v_high = v * 2
    v_third = v / 3
    r1 = Vec3(-R, 0, 0)
    r2 = Vec3(R, 0, 0)
    v1 = Vec3(0, -v, 0)
    v2 = Vec3(0, v, 0)
    r1_data, r2_data = [], []
    runge1, runge2 = [], []
    eccentr1, eccentr2 = [], []
    for i in range(n_steps + 1):
        r1_data.append(r1)
        r2_data.append(r2)
        rlv1 = Vec3.cross(v1, Vec3.cross(r1, v1)) - r1
        rlv2 = Vec3.cross(v2, Vec3.cross(r2, v2)) - r2
        ecc1 = math.sqrt(rlv1.abs_sq())
        ecc2 = math.sqrt(rlv2.abs_sq())
        runge1.append(rlv1)
        runge2.append(rlv2)
        eccentr1.append(ecc1)
        eccentr2.append(ecc2)
        r1, r2, v1, v2 = step(r1, r2, v1, v2, time_step)
        print("\rcalculation progress: t = {:.2f} / {:.2f} ({:.2f}%)".format(
            i * time_step, n_steps * time_step, 100 * i / n_steps),
              end="")
    # return r1_data, r2_data, eccentr1, eccentr2
    return r1, r2, v1, v2
Ejemplo n.º 2
0
 def __init__(self,lookfrom,lookat,vup,vfov,aspect,aperture,focus_dist):
   self.lens_radius = aperture /2
   theta = vfov * math.pi/180
   half_height = math.tan(theta/2)
   half_width = aspect * half_height
   self.origin = lookfrom
   self.w = Vec3.unit_vector(lookfrom -lookat)
   self.u = Vec3.unit_vector(Vec3.cross(vup,self.w))
   self.v = Vec3.cross(self.w,self.u)
   self.lower_left_corner = self.origin - half_width*focus_dist*self.u -half_height*focus_dist*self.v -focus_dist*self.w
   self.horizontal = 2*half_width*focus_dist*self.u
   self.vertical = 2*half_height*focus_dist*self.v
 def __init__(self, lookfrom, lookat, vup, vfov, aspect, aperture,
              focus_dist, t0, t1):
     self.time0 = t0
     self.time1 = t1
     self.lens_radius = aperture / 2
     theta = vfov * math.pi / 180
     half_height = math.tan(theta / 2)
     half_width = aspect * half_height
     self.origin = lookfrom
     self.w = Vec3.unit_vector(lookfrom - lookat)
     self.u = Vec3.unit_vector(Vec3.cross(vup, self.w))
     self.v = Vec3.cross(self.w, self.u)
     self.lower_left_corner = self.origin - half_width * focus_dist * self.u - half_height * focus_dist * self.v - focus_dist * self.w
     self.horizontal = 2 * half_width * focus_dist * self.u
     self.vertical = 2 * half_height * focus_dist * self.v
Ejemplo n.º 4
0
    def __init__(self,
                 look_from: Vec3 = Vec3(3.0, 3.0, 2.0),
                 look_at: Vec3 = Vec3(0.0, 0.0, -1.0),
                 vec_up: Vec3 = Vec3(0.0, 1.0, 0.0),
                 v_fov: float = 90.0,
                 aspect: float = 1.0,
                 aperture: float = 0.0,
                 focus_dist: float = 1.0):

        self.lens_radius = aperture / 2.0

        theta = v_fov * 3.14159 / 180.0
        half_height = math.tan(theta / 2.0)
        half_width = aspect * half_height

        w = unit_vector(look_from - look_at)
        self.u = unit_vector(vec_up.cross(w))
        self.v = w.cross(self.u)

        self.origin = look_from
        self.upper_left_corner = look_from - \
                                 half_width*self.u*focus_dist + \
                                 half_height*self.v*focus_dist - w*focus_dist
        self.horizontal = 2 * half_width * self.u * focus_dist
        self.vertical = -2 * half_height * self.v * focus_dist
Ejemplo n.º 5
0
    def createFromVectors(v1, v2):
        """ Function createFromVectors expects two 3d vectors. Quat has the Sofa format i.e (x,y,z,w).

        Examples:

        >>> q = Quat.createFromVectors([1,0,0],[0,1,0])
        >>> print(q)
        [0.,0.,0.707,0.707]
        """
        from quat import Quat
        from vec3 import Vec3
        from math import sqrt
        q = Quat()
        v = Vec3.cross(v1, v2)
        q[0:3] = v
        q[3] = sqrt((Vec3(v1).getNorm()**2) *
                    (Vec3(v2).getNorm()**2)) + Vec3.dot(v1, v2)
        q.normalize()
        return q
Ejemplo n.º 6
0
 def get_normal(self):
     return Vec3.cross(self.direction1, self.direction2).get_unit()
Ejemplo n.º 7
0
def leapfrog(R, v, time_step, n_steps):
    r1 = Vec3(-R, 0, 0)
    r2 = Vec3(R, 0, 0)
    v1 = Vec3(0, -v, 0)
    v2 = Vec3(0, v, 0)
    r1_neu, r2_neu, v1, v2 = step(r1, r2, v1, v2, (time_step / 2))
    r1_data, r2_data = [], []
    runge1, runge2 = [], []
    eccentr1, eccentr2 = [], []
    r1_data.append(r1)
    r2_data.append(r2)
    rlv1 = Vec3.cross(v1, Vec3.cross(r1, v1)) - r1
    rlv2 = Vec3.cross(v2, Vec3.cross(r2, v2)) - r2
    ecc1 = math.sqrt(rlv1.abs_sq())
    ecc2 = math.sqrt(rlv2.abs_sq())
    runge1.append(rlv1)
    runge2.append(rlv2)
    eccentr1.append(ecc1)
    eccentr2.append(ecc2)
    for i in range(n_steps - 1):
        r1, r2, v1, v2 = step1(r1, r2, v1, v2, time_step)
        r1_data.append(r1)
        r2_data.append(r2)
        rlv1 = Vec3.cross(v1, Vec3.cross(r1, v1)) - r1
        rlv2 = Vec3.cross(v2, Vec3.cross(r2, v2)) - r2
        ecc1 = math.sqrt(rlv1.abs_sq())
        ecc2 = math.sqrt(rlv2.abs_sq())
        runge1.append(rlv1)
        runge2.append(rlv2)
        eccentr1.append(ecc1)
        eccentr2.append(ecc2)
        print("\rcalculation progress: t = {:.2f} / {:.2f} ({:.2f}%)".format(
            i * time_step, n_steps * time_step, 100 * i / n_steps),
              end="")
    r1, r2, v1_neu, v2_neu = step(r1, r2, v1, v2, (time_step / 2))
    r1_data.append(r1)
    r2_data.append(r2)
    rlv1 = Vec3.cross(v1, Vec3.cross(r1, v1)) - r1
    rlv2 = Vec3.cross(v2, Vec3.cross(r2, v2)) - r2
    ecc1 = math.sqrt(rlv1.abs_sq())
    ecc2 = math.sqrt(rlv2.abs_sq())
    runge1.append(rlv1)
    runge2.append(rlv2)
    eccentr1.append(ecc1)
    eccentr2.append(ecc2)
    return r1, r2, v1, v2