当前位置: 首页>>代码示例>>Python>>正文


Python Vector.cross方法代码示例

本文整理汇总了Python中mathutils.Vector.cross方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.cross方法的具体用法?Python Vector.cross怎么用?Python Vector.cross使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathutils.Vector的用法示例。


在下文中一共展示了Vector.cross方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: nautical_euler_from_axes

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def nautical_euler_from_axes(forward, right):
    x = Vector(right)
    y = Vector(forward)
    
    world_x = Vector((1, 0, 0))
    world_z = Vector((0, 0, 1))
    
    if abs(y.z) > (1 - 1e-12): # sufficiently close to vertical
        roll = 0.0
        xdir = x.copy()
    else:
        xdir = y.cross(world_z)
        rollPos = angle_signed(-y, x, xdir, 0.0)
        rollNeg = angle_signed(-y, x, -xdir, 0.0)
        if abs(rollNeg) < abs(rollPos):
            roll = rollNeg
            xdir = -xdir
        else:
            roll = rollPos
    xdir = Vector((xdir.x, xdir.y, 0)).normalized()
    
    yaw = angle_signed(-world_z, xdir, world_x, 0.0)
    
    zdir = xdir.cross(y).normalized()
    pitch = angle_signed(-xdir, zdir, world_z, 0.0)
    
    return Euler((pitch, roll, yaw), 'YXZ')
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:29,代码来源:utils_math.py

示例2: arbitrary_x_axis

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
 def arbitrary_x_axis(extrusion_normal):
     world_y = Vector((0, 1, 0))
     world_z = Vector((0, 0, 1))
     if abs(extrusion_normal[0]) < 1 / 64 and abs(extrusion_normal[1]) < 1 / 64:
         a_x = world_y.cross(extrusion_normal)
     else:
         a_x = world_z.cross(extrusion_normal)
     a_x.normalize()
     return a_x, extrusion_normal.cross(a_x)
开发者ID:fjuhec,项目名称:blender-addons,代码行数:11,代码来源:convert.py

示例3: _gimbal_xyz

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
 def _gimbal_xyz(self, context, am):
     rotobj = (context.active_pose_bone if context.mode == 'POSE' else None) or context.active_object
     
     if (not rotobj) or (rotobj.rotation_mode == 'QUATERNION'):
         if not am: am = self.calc_active_matrix(context)
         xyz = am.col[:3]
     elif rotobj.rotation_mode == 'AXIS_ANGLE':
         aa = rotobj.rotation_axis_angle
         z = Vector(aa[1:]).normalized()
         q = Vector((0,0,1)).rotation_difference(z)
         x = (q * Vector((1,0,0))).normalized()
         y = z.cross(x)
     else:
         e = rotobj.rotation_euler
         m = Matrix.Identity(3)
         for e_ax in rotobj.rotation_mode:
             m = Matrix.Rotation(getattr(e, e_ax.lower()), 3, e_ax) * m
         x, y, z = m.col[:3]
     
     if not xyz:
         m = BlUtil.Object.matrix_parent(rotobj)
         x.rotate(m)
         y.rotate(m)
         z.rotate(m)
         xyz = x, y, z
     
     return xyz
开发者ID:IBaaNB,项目名称:blenderpython,代码行数:29,代码来源:coordsystems.py

示例4: __get

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
 def __get(self): # in object axes
     world_x = Vector((1, 0, 0))
     world_z = Vector((0, 0, 1))
     
     x = self.right # right
     y = self.forward # forward
     z = self.up # up
     
     if abs(y.z) > (1 - 1e-12): # sufficiently close to vertical
         roll = 0.0
         xdir = x.copy()
     else:
         xdir = y.cross(world_z)
         rollPos = angle_signed(-y, x, xdir, 0.0)
         rollNeg = angle_signed(-y, x, -xdir, 0.0)
         if abs(rollNeg) < abs(rollPos):
             roll = rollNeg
             xdir = -xdir
         else:
             roll = rollPos
     xdir = Vector((xdir.x, xdir.y, 0)).normalized()
     
     yaw = angle_signed(-world_z, xdir, world_x, 0.0)
     
     zdir = xdir.cross(y).normalized()
     pitch = angle_signed(-xdir, zdir, world_z, 0.0)
     
     return Euler((pitch, roll, yaw), 'YXZ')
开发者ID:BitByte01,项目名称:myblendercontrib,代码行数:30,代码来源:utils_view3d.py

示例5: add_f_curve_modifiers

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def add_f_curve_modifiers(armature_object, strength, speed):
    wind_vector = Vector((1, 0, 0)) * strength

    fcurves = armature_object.animation_data.action.fcurves
    for f in fcurves:
        for m in f.modifiers:
            f.modifiers.remove(m)

    bones = organize_bones(armature_object)

    for b in bones:
        mass = b.bone.tail_radius ** 2 * b.length
        barycenter = b.tail * mass
        for c in b.children:
            mass += c["mass"]
            barycenter += Vector(c["barycenter"])
        b["mass"] = mass
        b["barycenter"] = barycenter
        barycenter /= mass

        b.rotation_mode = 'XYZ'
        b.keyframe_insert('rotation_euler', frame=0, index=0)
        b.keyframe_insert('rotation_euler', frame=0, index=2)

    fcurves = armature_object.animation_data.action.fcurves


    for i in range(len(bones)):
        f0 = fcurves[2 * i]
        f1 = fcurves[2 * i + 1]
        b = bones[i]

        i_base = b.matrix.to_3x3().inverted()
        bone_vector = b.tail - b.head

        inertia_moment = bone_vector.length ** 2 * bones[i]["mass"] / 10000
        damping = 0.5 * b.bone.tail_radius
        stiffness = b.bone.tail_radius ** 2 / b.length * 800
        if b.parent is not None and len(b.parent.children) > 1:
            stiffness *= 2
            # torque /= 3
        # else:
        #     torque = Vector((0, 0, 0))
        torque = i_base * wind_vector.cross(bone_vector) / (b.bone.tail_radius) / 1000

        f = sqrt(abs(damping ** 2 - 4 * inertia_moment * stiffness)) / (5*b.bone.tail_radius) * speed

        x_amplitude = torque.x
        z_amplitude = torque.z

        m0 = f0.modifiers.new(type='FNGENERATOR')
        m1 = f1.modifiers.new(type='FNGENERATOR')
        m0.function_type = 'SIN'
        m1.function_type = 'SIN'
        m0.amplitude = x_amplitude
        m1.amplitude = z_amplitude
        m0.phase_multiplier = f
        m1.phase_multiplier = f
        m0.value_offset = x_amplitude * 3
        m1.value_offset = z_amplitude * 3
开发者ID:MaximeHerpin,项目名称:Blender-Modular-tree-addon,代码行数:62,代码来源:wind.py

示例6: focus_view_on

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def focus_view_on(region_3d, location):
    r3d = region_3d

    a = r3d.view_location.copy()
    b = location
    mm = r3d.view_matrix.inverted()

    vr = mm.to_3x3()
    loc = mm.translation

    n = (a-loc).cross(b-loc).normalized()
    alp = math.acos( max(-1.0,min(1.0,  (a-loc).normalized().dot( (b-loc).normalized() )  )))

    zero = Vector()
    u0,v0,w0 = vr.transposed()
    u = rot_on( zero, n, alp, u0 )
    v = rot_on( zero, n, alp, v0 )
    w = rot_on( zero, n, alp, w0 )

    if bpy.context.user_preferences.inputs.view_rotate_method == 'TURNTABLE':
        ez = Vector((0,0,1))
        u2 = ez.cross(w)
        v2 = w.cross(u2)
        u,v = u2,v2

    vr2 = Matrix((u,v,w)).transposed()

    mm2 = vr2.to_4x4()
    mm2[0][3] = loc[0]
    mm2[1][3] = loc[1]
    mm2[2][3] = loc[2]

    dist0 = (loc-location).length
    r3d.view_distance = dist0
    r3d.view_matrix = mm2.inverted()
开发者ID:a-nakanosora,项目名称:Focus-on-Mouse,代码行数:37,代码来源:view3d_focus_on_mouse.py

示例7: rotate

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
  def rotate(self,v):
    up_axis = Vector((0.0, 0.0, 1.0))
    angle = v.angle(up_axis, 0)
    rotation_axis = up_axis.cross(v)
    bpy.ops.transform.rotate(value=angle,axis=rotation_axis)

    return
开发者ID:inconvergent,项目名称:mesh_network,代码行数:9,代码来源:mesh_network.py

示例8: vec_roll_to_mat3

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def vec_roll_to_mat3(axis, roll):
    """Computes 3x3 Matrix from rotation axis and its roll.

    :param axis: Rotation
    :type axis: Vector
    :param roll: Roll
    :type roll: float
    :return: 3x3 Matrix
    :rtype: Matrix
    """
    nor = axis.normalized()
    target = Vector((0, 1, 0))
    axis = target.cross(nor)

    if axis.dot(axis) > 1.0e-9:
        axis.normalize()
        theta = _math_utils.angle_normalized_v3v3(target, nor)
        b_matrix = Matrix.Rotation(theta, 4, axis)
    else:
        if target.dot(nor) > 0:
            up_or_down = 1.0
        else:
            up_or_down = -1.0

        b_matrix = Matrix()
        b_matrix[0] = (up_or_down, 0, 0, 0)
        b_matrix[1] = (0, up_or_down, 0, 0)
        b_matrix[2] = (0, 0, 1, 0)
        b_matrix[3] = (0, 0, 0, 1)

    roll_matrix = Matrix.Rotation(roll, 4, nor)
    return (roll_matrix * b_matrix).to_3x3()
开发者ID:P-casper1,项目名称:BlenderTools,代码行数:34,代码来源:convert.py

示例9: get_align_matrix

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def get_align_matrix(location, normal):
    up = Vector((0, 0, 1))
    angle = normal.angle(up)
    axis = up.cross(normal)
    mat_rot = Matrix.Rotation(angle, 4, axis)
    mat_loc = Matrix.Translation(location)
    mat_align = mat_rot * mat_loc
    return mat_align
开发者ID:fjuhec,项目名称:blender-addons,代码行数:10,代码来源:drop_to_ground.py

示例10: find_norm_vectors

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def find_norm_vectors(mesh, vert_dict):
    vertices = list(vert_dict.keys())
    for vert in vertices:
        edge_vectors = []
        for edge in vert_dict[vert].edges:
            if vert == edge[0]:
                vec = mesh.vertices[edge[0]].co.copy() - mesh.vertices[edge[1]].co.copy()
            else:
                vec = mesh.vertices[edge[1]].co.copy() - mesh.vertices[edge[0]].co.copy()
            edge_vectors.append(vec/vec.length)
        vec1 = Vector.cross(edge_vectors[0], edge_vectors[1])
        edges_vec = edge_vectors[1] + edge_vectors[0]
        norm_vec = Vector.cross(vec1, edges_vec)
        if norm_vec.length < 1e-12:           #hackish fix for flat surfaces and straight edges
            norm_vec = edge_vectors[0] 
        
        vert_dict[vert].new_index = len(mesh.vertices) + vertices.index(vert)
        vert_dict[vert].norm_vec = norm_vec
        vert_dict[vert].edge_vec = edge_vectors[0]
开发者ID:mik0001,项目名称:Blender,代码行数:21,代码来源:mesh_inset_extrude.py

示例11: set_bonded

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def set_bonded(atom,b):
    """Sets the positions of all atoms bonded to atom.
    
    atom: Atom object
    rotate: Boolean defining whether or not to rotate tetrahedron around the z-axis
    b: bond length
    """
    x = 0
    y = 0
    z = 0
    b = b*sqrt(atom.radius)
    
    bonds = atom.bonds
    
    #Differences in position between central atom and bonded atom
    for item in bonds:
        if isinstance(item, Atom):
            x = atom.pos[0] - item.pos[0]
            y = atom.pos[1] - item.pos[1]
            z = atom.pos[2] - item.pos[2]
            break
   
    n = math.radians(109.5)
    n2 = pi*2/3

    #Represents tetrahedron base centered at (0,0,0)
    v1 = Vector((b*sin(n),0,b*cos(n)))
    v2 = Vector((b*cos(n2),b*sin(n2),b*cos(n)))
    v3 = Vector((b*cos(2*n2),b*sin(2*n2),b*cos(n)))
    
    offset = (Vector((atom.pos)))

    top= Vector((0,0,-b))
    diff = Vector((x,y,z))

    axis = top.cross(diff)
    a = -(top.angle(diff, 0))
    
    m = Matrix.Rotation(a,3,axis)
    #Rotates the tetrahedron base to align itself with the starting vector
    v1 = v1*m
    v2 = v2*m
    v3 = v3*m
    
    #Sets the positions of bonded atoms to locations in the tetrahedron, scales bond lengths and moves tetrahedron
    if len(bonds) >1:
        if isinstance(bonds[1], Atom):
            bonds[1].pos = v1*sqrt(bonds[1].radius)+offset
    if len(bonds) >2:
        if isinstance(bonds[2], Atom):
            bonds[2].pos = v2*sqrt(bonds[2].radius)+offset
    if len(bonds)>3:
        if isinstance(bonds[3],Atom):
            bonds[3].pos = v3*sqrt(bonds[3].radius)+offset
开发者ID:ETumang,项目名称:MolecularModeling,代码行数:56,代码来源:moleculeDisplay.py

示例12: make_strut

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def make_strut(v1, v2, id, od, n, solid, loops):
    v1 = Vector(v1)
    v2 = Vector(v2)
    axis = v2 - v1
    pos = [(0, od / 2)]
    if loops:
        pos += [((od - id) / 2, od / 2),
                (axis.length - (od - id) / 2, od / 2)]
    pos += [(axis.length, od / 2)]
    if solid:
        pos += [(axis.length, id / 2)]
        if loops:
            pos += [(axis.length - (od - id) / 2, id / 2),
                    ((od - id) / 2, id / 2)]
        pos += [(0, id / 2)]
    vps = len(pos)
    fps = vps
    if not solid:
        fps -= 1
    fw = axis.copy()
    fw.normalize()
    if (abs(axis[0] / axis.length) < 1e-5
        and abs(axis[1] / axis.length) < 1e-5):
        up = Vector((-1, 0, 0))
    else:
        up = Vector((0, 0, 1))
    lf = up.cross(fw)
    lf.normalize()
    up = fw.cross(lf)
    mat = Matrix((fw, lf, up))
    mat.transpose()
    verts = [None] * n * vps
    faces = [None] * n * fps
    for i in range(n):
        base = (i - 1) * vps
        x = cossin[i][0]
        y = cossin[i][1]
        for j in range(vps):
            p = Vector((pos[j][0], pos[j][1] * x, pos[j][1] * y))
            p = mat * p
            verts[i * vps + j] = p + v1
        if i:
            for j in range(fps):
                f = (i - 1) * fps + j
                faces[f] = [base + j, base + vps + j,
                            base + vps + (j + 1) % vps, base + (j + 1) % vps]
    base = len(verts) - vps
    i = n
    for j in range(fps):
        f = (i - 1) * fps + j
        faces[f] = [base + j, j, (j + 1) % vps, base + (j + 1) % vps]
    #print(verts,faces)
    return verts, faces
开发者ID:luaman,项目名称:qforge-1,代码行数:55,代码来源:MakeStruts.py

示例13: calc_average_area

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def calc_average_area(mdl):
    frame = mdl.frames[0]
    if frame.type:
        frame = frame.frames[0]
    totalarea = 0.0
    for tri in mdl.tris:
        verts = tuple(map(lambda i: frame.verts[i], tri.verts))
        a = Vector(verts[0].r) - Vector(verts[1].r)
        b = Vector(verts[2].r) - Vector(verts[1].r)
        c = a.cross(b)
        totalarea += (c * c) ** 0.5 / 2.0
    return totalarea / len(mdl.tris)
开发者ID:victorfeitosa,项目名称:hexen2-mdl-export-import,代码行数:14,代码来源:export_mdl.py

示例14: calcRotAngle

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
    def calcRotAngle(self, axis, nor_x, nor_y, nor_z):
        theta = 0
        vector_z = Vector((0.0, 0.0, 1.0))
        vector_n = None
        vector_cross = None

        if axis == 'X':
            vector_n = Vector((0.0, nor_y, nor_z))
            theta = vector_z.angle(vector_n, 999)
            vector_cross = vector_n.cross(vector_z)
            if vector_cross.x < 0:
                theta = -(theta)
        elif axis == 'Y':
            vector_n = Vector((nor_x, 0.0, nor_z))
            theta = vector_z.angle(vector_n, 999)
            vector_cross = vector_n.cross(vector_z)
            if vector_cross.y < 0:
                theta = -(theta)
        else:
            pass

        return theta
开发者ID:Italic-,项目名称:blenderpython,代码行数:24,代码来源:uv_prj_from_normal.py

示例15: vec_roll_to_mat3

# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import cross [as 别名]
def vec_roll_to_mat3(vec, roll):
	target = Vector((0,1,0))
	nor = vec.normalized()
	axis = target.cross(nor)
	if axis.dot(axis) > 0.000001:
		axis.normalize()
		theta = target.angle(nor)
		bMatrix = Matrix.Rotation(theta, 3, axis)
	else:
		updown = 1 if target.dot(nor) > 0 else -1
		bMatrix = Matrix.Scale(updown, 3)
	rMatrix = Matrix.Rotation(roll, 3, nor)
	mat = rMatrix * bMatrix
	return mat
开发者ID:uthaman22,项目名称:asstools,代码行数:16,代码来源:iqe_import.py


注:本文中的mathutils.Vector.cross方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。