Example #1
0
    def execute(self, context):
        p0_ref = context.scene.Fractals.p0
        p1_ref = context.scene.Fractals.p1

        step_size = context.scene.Fractals.stepSize
        p0 = vec((p0_ref[0], p0_ref[1], p0_ref[2]))
        p1 = vec((p1_ref[0], p1_ref[1], p1_ref[2]))

        control = context.scene.Fractals.fractalsEnum

        tris = []

        for x, y, z in grid(p0, p1, step_size):
            vertexpos = []
            vertexval = []

            for dx, dy, dz in coords(step_size):
                pos = vec((x + dx, y + dy, z + dz))
                vertexpos.append(pos)
                if control == 'julia':
                    vertexval.append(iterate4DJuliaSet(pos))
                elif control == 'mandelbulb':
                    vertexval.append(iterateMandelBulb(pos))
            tris.extend(polygonise(vertexpos, vertexval))

        vertices, faces = genFaces(tris)
        genMesh(context.scene.Fractals.fractalName, vertices, faces)

        return {'FINISHED'}
Example #2
0
 def execute(self, context):
     p0_ref = context.scene.Fractals.p0
     p1_ref = context.scene.Fractals.p1
     
     step_size = context.scene.Fractals.stepSize
     p0 = vec((p0_ref[0],p0_ref[1], p0_ref[2]))
     p1 = vec((p1_ref[0],p1_ref[1], p1_ref[2]))
     
     control = context.scene.Fractals.fractalsEnum
     
     tris = []
    
     for x,y,z in grid(p0,p1,step_size):
         vertexpos = []
         vertexval = []
         
         for dx,dy,dz in coords(step_size):
             pos = vec((x+dx,y+dy,z+dz))
             vertexpos.append(pos)
             if control == 'julia':
                 vertexval.append(iterate4DJuliaSet(pos))
             elif control == 'mandelbulb':
                 vertexval.append(iterateMandelBulb(pos))
         tris.extend(polygonise(vertexpos,vertexval))
 
     vertices, faces = genFaces(tris)
     genMesh(context.scene.Fractals.fractalName, vertices, faces)
     
     return{'FINISHED'}
Example #3
0
    def compute_traveled_dist(self):
        """Return a float representing the distance between origin and the current position"""

        # Get current position
        self.position = self.body_obj.worldTransform * vec((0, 0, 0))

        # Get distance
        self.dist = vec(self.position - self.origin).length

        return 
    def __init__(self, params_, simulator):
        """
        Class initialization
        :param params_: Dictionary containing parameter for the muscle
        :param simulator: SimulatorUtils class to access utility functions
        """

        self.n_iter = 0
        self.params = params_
        self.simulator = simulator
        self.name = self.params["name"]
        self.active = True

        self.logger = logging.getLogger(params_["logger"])

        # Check if object exists
        self.obj1 = self.simulator.get_object(self.params["obj_1"])
        if self.obj1 is None:
            self.logger.error("Muscle " + self.name + " deactivated: first extremity object doesn't exit." +
                              " Check your configuration file!")
            self.active = False

        self.obj2 = self.simulator.get_object(self.params["obj_2"])
        if self.obj2 is None:
            self.logger.error("Muscle " + self.name + " deactivated: second extremity object doesn't exit." +
                              " Check your configuration file!")
            self.active = False

        # Points of application in local coordinates
        if self.params["anch_1"] is None:
            self.logger.error("You have not defined the first application point of muscle " + self.name +
                              "! Center is taken by default. This may results in erroneous simulation")
            self.params["anch_1"] = [0.0, 0.0, 0.0]
        if self.params["anch_2"] is None:
            self.logger.error("You have not defined the second application point of muscle " + self.name +
                              "! Center is taken by default. This may results in erroneous simulation")
            self.params["anch_2"] = [0.0, 0.0, 0.0]
        self.app_point_1 = vec((self.params["anch_1"]))
        self.app_point_2 = vec((self.params["anch_2"]))

        self.app_point_1_world = None
        self.app_point_2_world = None
        self.length = 0.
        self.velocity_1 = 0.
        self.velocity_2 = 0.
        self.force = vec((0, 0, 0))
        self.ctrl_sig = None

        if self.active:
            self.update_position()
            self.update_velocity()
Example #5
0
    def __init__(self, scene_, params_):
        """Class initialization"""
        self.n_iter = 0
        self.scene = scene_
        self.params = params_
        self.name = self.params["name"]
        self.active = True

        self.logger = logging.getLogger(params_["logger"])

        # Check if onject exist
        if not self.params["obj_1"] in self.scene.objects:
            self.logger.error("Muscle " + self.name + " deactivated: first extremity object doesn't exit." +
                  " Check your configuration file!")
            self.active = False
        else:
            self.obj1 = self.scene.objects[self.params["obj_1"]]
        if not self.params["obj_2"] in self.scene.objects:
            self.logger.error("Muscle " + self.name + " deactivated: second extremity object doesn't exit." +
                " Check your configuration file!")
            self.active = False
        else:
            self.obj2 = self.scene.objects[self.params["obj_2"]]

        # Points of application in local coordinates
        if self.params["anch_1"] is None:
            self.logger.error("You have not defined the first application point of muscle " + self.name +
                  "! Center is taken by default. This may results in erroneous simulation")
            self.params["anch_1"] = [0.0, 0.0, 0.0]
        if self.params["anch_2"] is None:
            self.logger.error("You have not defined the second application point of muscle " + self.name +
                  "! Center is taken by default. This may results in erroneous simulation")
            self.params["anch_2"] = [0.0, 0.0, 0.0]
        self.app_point_1 = vec((self.params["anch_1"]))
        self.app_point_2 = vec((self.params["anch_2"]))

        if self.active:
            self.app_point_1_world = self.obj1.worldTransform * self.app_point_1  # global coordinates of app point 1 in m
            self.app_point_2_world = self.obj2.worldTransform * self.app_point_2  # global coordinates of app point 2 in m
Example #6
0
    def __init__(self, scene_, config_):
        """Class initialization"""

        self.n_iter = 0
        self.scene = scene_
        self.config = config_
        self.logger = config_.logger
        self.muscle_type = self.config.muscle_type + "(self.scene, muscle_config)"
        self.name = self.config.body["name"]

        # Get body object
        if not self.config.body["obj"] in self.scene.objects:
            self.logger.error("Body " + self.name + " doesn't exit. Check your configuration file!")
            self.active = False
        else:
            self.body_obj = self.scene.objects[self.config.body["obj"]]

        # Create and init variables for loss function
        self.origin = self.body_obj.worldTransform * vec((0, 0, 0))
        self.position = self.origin
        self.dist = vec(self.position - self.origin).length
        self.powers = []
        self.av_power = 0.0
        self.loss_fct = 0.0

        # Create 4 legs
        self.l_fo_leg = Foreleg(scene_, config_, "L")
        self.r_fo_leg = Foreleg(scene_, config_, "R")
        self.l_ba_leg = Backleg(scene_, config_, "L")
        self.r_ba_leg = Backleg(scene_, config_, "R")

        # Create the brain object
        self.brain = Brain(scene_, config_)

        # Create the muscles objects following config
        self.muscles = []
        for muscle_config in self.config.body["muscles"]:
            self.muscles.append(eval(self.muscle_type))
Example #7
0
def z_to_the_n(old_z, n):
    x = old_z[0]
    y = old_z[1]
    z = old_z[2]
    
    r = sqrt(x*x + y*y + z*z)
    theta = atan2(sqrt(x*x + y*y),z)
    phi = atan2(y,x);
    
    new_z = vec()
    new_z.x = pow(r,n) * sin(theta*n) * cos(phi*n);
    new_z.y = pow(r,n) * sin(theta*n) * sin(phi*n);
    new_z.z = pow(r,n) * cos(theta*n)
    
    return new_z
Example #8
0
def z_to_the_n(old_z, n):
    x = old_z[0]
    y = old_z[1]
    z = old_z[2]

    r = sqrt(x * x + y * y + z * z)
    theta = atan2(sqrt(x * x + y * y), z)
    phi = atan2(y, x)

    new_z = vec()
    new_z.x = pow(r, n) * sin(theta * n) * cos(phi * n)
    new_z.y = pow(r, n) * sin(theta * n) * sin(phi * n)
    new_z.z = pow(r, n) * cos(theta * n)

    return new_z
Example #9
0
    def __init__(self, scene_, params_):
        """Class initialization. Requires scene, controller as well as two object and the local point of application \
        of the spring forces"""
        Muscle.__init__(self, scene_, params_)

        # Model constants and variables
        self.k = self.params["k"]  # scalar in N/m??
        self.c = self.params["c"]  # scalar in N.s/m??
        self.k_cont = self.params["kc"]  # no dimension
        self.ctrl_sig = None
        if self.active:
            self.l = self.app_point_2_world - self.app_point_1_world  # global coordinate vector between app points in m
            self.v_1 = self.obj1.getVelocity(self.app_point_1) # vector in m/s??
            self.v_2 = self.obj2.getVelocity(self.app_point_2) # vector in m/s??
            v = self.v_2 - self.v_1 # vector in m/s??
            self.v_norm = v.dot(self.l.normalized()) * self.l.normalized()  # normal velocity vector in m/s??
            self.l0 = self.params["kl0"] * self.l.length  # scalar in m??
            self.l_cont = self.l0  # scalar in m??
            self.force = vec((0, 0, 0)) # vector in N??
Example #10
0
def iterateMandelBulb(c):
    z = vec()
    n = bpy.context.scene.Fractals.mandelbulb.power
    threshold = bpy.context.scene.Fractals.mandelbulb.bailout
    max_iterations = bpy.context.scene.Fractals.mandelbulb.maxIterations
    #n = 8 # make hyperparameter
    iterations = 0
    converged = 1
    
    while(True):
        z = z_to_the_n(z,n) + c
        
        iterations += 1 
        
        if iterations > max_iterations:
            break 
        
        if z.length > threshold:
            converged = 0
            break          
    return converged
Example #11
0
def iterateMandelBulb(c):
    z = vec()
    n = bpy.context.scene.Fractals.mandelbulb.power
    threshold = bpy.context.scene.Fractals.mandelbulb.bailout
    max_iterations = bpy.context.scene.Fractals.mandelbulb.maxIterations
    #n = 8 # make hyperparameter
    iterations = 0
    converged = 1

    while (True):
        z = z_to_the_n(z, n) + c

        iterations += 1

        if iterations > max_iterations:
            break

        if z.length > threshold:
            converged = 0
            break
    return converged
Example #12
0
 def compute_traveled_dist(self):
     """Return a float representing the distance between origin and the current position"""
     return vec(self.simulator.update_world_position(self.body_obj, self.origin) - self.origin).x