本文整理汇总了Python中mathutils.Vector.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.rotate方法的具体用法?Python Vector.rotate怎么用?Python Vector.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mathutils.Vector
的用法示例。
在下文中一共展示了Vector.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: va
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def va(vx, vz, iang, sang, n): # shortcut Verts.append
for i in range(n):
v = Vector((vx, 0, vz))
ai = sang + iang*i
E_rot = Euler((0, 0, ai), 'XYZ')
v.rotate(E_rot)
Verts.append((v.x, v.y, v.z))
示例2: make_verts
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def make_verts(n_petals=8, vp_petal=20, profile_radius=1.3, amp=1.0):
# variables
z_float = 0.0
n_verts = n_petals * vp_petal
section_angle = 360.0 / n_verts
position = (2 * (pi / (n_verts / n_petals)))
# consumables
Verts = []
# makes vertex coordinates
for i in range(n_verts):
# difference is a function of the position on the circumference
difference = amp * cos(i * position)
arm = profile_radius + difference
ampline = Vector((arm, 0.0, 0.0))
rad_angle = radians(section_angle * i)
myEuler = Euler((0.0, 0.0, rad_angle), 'XYZ')
# changes the vector in place, successive calls are accumulative
# we reset at the start of the loop.
ampline.rotate(myEuler)
x_float = ampline.x
y_float = ampline.y
Verts.append((x_float, y_float, z_float))
return Verts
示例3: _gimbal_xyz
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [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
示例4: shape_circle
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def shape_circle(context, orientation):
center = context.scene.cursor_location
active = context.active_object
zed = active.location[2]
base_dir = active.location.xy - center.xy
if orientation == 'XY':
zero_dir = get_xy(base_dir).resized(3)
else:
zero_dir = base_dir.xy.resized(3)
num_objects = len(context.selected_objects)
delta_angle = 2 * math.pi / num_objects
# sort objects based on angle to center
sorted_objects = sorted(context.selected_objects, key=lambda ob: get_angle(base_dir, ob, center))
for i in range(num_objects):
angle = delta_angle * i
euler = Euler((0, 0, -angle))
direction = Vector(zero_dir)
direction.rotate(euler)
sorted_objects[i].location = center + direction
sorted_objects[i].location[2] = zed
示例5: direction_rotate
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def direction_rotate(angle):
vec = Vector((0, 0, 1))
vec.rotate(Euler((tilt, 0, 0), 'ZYX'))
vec.rotate(Euler((0, 0, angle)))
if simrot.relative_to_orbit:
vec = orbit_rotate(vec, simorbit)
return vec - orbit_normal * cos(tilt)
示例6: tilt_rotate
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def tilt_rotate(angle):
vec = Vector((0, 0, 1))
vec.rotate(Euler((angle, 0, 0), 'ZYX'))
vec.rotate(Euler((0, 0, direction)))
if simrot.relative_to_orbit:
vec = orbit_rotate(vec, simorbit)
return vec
示例7: make_coil
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def make_coil(self):
# variables and shortnames
amp = self.profile_radius
n_verts = self.num_verts
n_turns = self.num_turns
th = self.height / n_turns
ipt = self.iterations_per_turn
radius = self.coil_radius
diameter = radius * 2
two_pi = 2.0 * pi
section_angle = two_pi / n_verts
rad_slice = two_pi / ipt
total_segments = (ipt * n_turns) + 1
z_jump = self.height / total_segments
x_rotation = atan2(th / 2, diameter)
n = n_verts
Verts = []
for segment in range(total_segments):
rad_angle = rad_slice * segment
for i in range(n):
# create the vector
this_angle = section_angle * i
x_float = amp * sin(this_angle) + radius
z_float = amp * cos(this_angle)
v1 = Vector((x_float, 0.0, z_float))
# rotate it
xz_euler = Euler((-x_rotation, 0.0, -rad_angle), 'XYZ')
v1.rotate(xz_euler)
# add extra z height per segment
v1 += Vector((0, 0, (segment * z_jump)))
# append it
Verts.append(v1)
Faces = []
# skin it, normals facing outwards
for t in range(total_segments-1):
for i in range(n-1):
p0 = i + (n*t)
p1 = i + (n*t) + 1
p2 = i + (n*t + n) + 1
p3 = i + (n*t + n)
Faces.append([p3,p2,p1,p0])
p0 = n*t
p1 = n*t + n
p2 = n*t + (2 * n) - 1
p3 = n*t + n-1
Faces.append([p3,p2,p1,p0])
return Verts, Faces
示例8: to_3d
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def to_3d(vec, co=None, rot=None):
"""Take a 2D vector (or the XY of a 3D vector) and transform it
according to co and rot."""
newvec = Vector((vec[0], vec[1], 0))
if rot:
newvec.rotate(rot)
if co:
newvec += co
return newvec
示例9: rotation
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def rotation(self, xyz):
xyz = Euler(xyz, 'XYZ')
self._rotation = self.ProxyRotation(xyz)
for line in self._lines:
line.rotation = xyz
length = (line.position - self.position).length
pos = Vector([0,-length,0])
pos.rotate(xyz)
line.position = pos + self.position
示例10: make_coil
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def make_coil():
# variables
amp = prad
th = height / n_turns
ipt = n_iter
radius = crad
diameter = radius * 2
section_angle = 360.0 / n_verts
rad_slice = 2.0 * pi / ipt
total_segments = (ipt * n_turns) + 1
z_jump = height / total_segments
x_rotation = atan2(th / 2, diameter)
n = n_verts
Verts = []
for segment in range(total_segments):
rad_angle = rad_slice * segment
for i in range(n):
# create the vector
this_angle = section_angle * i
x_float = amp * sin(radians(this_angle)) + radius
z_float = amp * cos(radians(this_angle))
v1 = Vector((x_float, 0.0, z_float))
# rotate it
some_euler = Euler((-x_rotation, 0.0, -rad_angle), 'XYZ')
v1.rotate(some_euler)
# add extra z height per segment
v1 += Vector((0, 0, (segment * z_jump)))
# append it
Verts.append(v1.to_tuple())
Faces = []
for t in range(total_segments - 1):
for i in range(n - 1):
p0 = i + (n * t)
p1 = i + (n * t) + 1
p2 = i + (n * t + n) + 1
p3 = i + (n * t + n)
Faces.append([p0, p1, p2, p3])
p0 = n * t
p1 = n * t + n
p2 = n * t + (2 * n) - 1
p3 = n * t + n - 1
Faces.append([p0, p1, p2, p3])
return Verts, Faces
示例11: mirrorPlane
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def mirrorPlane(vertex, matrix):
vert = []
a = Matrix(matrix)
eul = a.to_euler()
normal = Vector((0.0, 0.0, 1.0))
normal.rotate(eul)
tras = Matrix.Translation(2*a.to_translation())
for i in vertex:
v = Vector(i)
r = v.reflect(normal)
vert.append((tras*r)[:])
return vert
示例12: sv_main
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def sv_main(n_petals=8, vp_petal=20, profile_radius=1.3, amp=1.0):
in_sockets = [
['s', 'Num Petals', n_petals],
['s', 'Verts per Petal', vp_petal],
['s', 'Profile Radius', profile_radius],
['s', 'Amp', amp],
]
from math import sin, cos, radians, pi
from mathutils import Vector, Euler
# variables
z_float = 0.0
n_verts = n_petals * vp_petal
section_angle = 360.0 / n_verts
position = (2 * (pi / (n_verts / n_petals)))
# consumables
Verts = []
Edges = []
# makes vertex coordinates
for i in range(n_verts):
# difference is a function of the position on the circumference
difference = amp * cos(i * position)
arm = profile_radius + difference
ampline = Vector((arm, 0.0, 0.0))
rad_angle = radians(section_angle * i)
myEuler = Euler((0.0, 0.0, rad_angle), 'XYZ')
# changes the vector in place, successive calls are accumulative
# we reset at the start of the loop.
ampline.rotate(myEuler)
x_float = ampline.x
y_float = ampline.y
Verts.append((x_float, y_float, z_float))
# makes edge keys
for i in range(n_verts):
if i == n_verts - 1:
Edges.append([i, 0])
break
Edges.append([i, i + 1])
out_sockets = [
['v', 'Verts', [Verts]],
['s', 'Edges', [Edges]],
]
return in_sockets, out_sockets
示例13: __init__
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
class Turtle:
def __init__(self, position=(0, 0, 0),direction =(0,0,1), orientation=(0, 1, 0),axe_rotation = (0,0,1), vitesse=1, angle=90,imperfection = 0.2):
self.position = Vector(position)
self.direction = Vector(direction).normalized()
self.orientation = Vector(orientation).normalized()
self.vitesse = vitesse
self.angle = radians(angle)
self.memoireEtat = []
self.comportement_initialisation()
self.imperfection = imperfection
def comportement_initialisation(self):
self.comportements = {
'+':self.comportement_plus,
'-':self.comportement_moins,
'F':self.comportement_F,
'[':self.comportement_save_etat,
']':self.comportement_restor_etat
}
def comportement_F(self):
p_debut = self.position.copy()
self.position += self.direction * self.vitesse
dx = (random() - 0.5) * self.imperfection
dy = (random() - 0.5) * self.imperfection
dz = (random() - 0.5) * self.imperfection
self.direction += Vector((dx,dy,dz))
p_fin = self.position.copy()
return Section(debut = p_debut,fin = p_fin)
def comportement_save_etat(self):
etat = (self.position.copy(),
self.direction.copy(),
self.vitesse,
self.angle)
self.memoireEtat.append(etat)
def comportement_restor_etat(self):
(self.position,
self.direction,
self.vitesse,
self.angle) = self.memoireEtat.pop()
def comportement_plus(self):
rotation = Matrix.Rotation(self.angle,4,self.orientation)
self.direction.rotate(rotation)
def comportement_moins(self):
rotation = Matrix.Rotation(- self.angle, 4,self.orientation)
self.direction.rotate(rotation)
def interpretation(self,s):
for char in s:
comportement = self.comportements[char]() if char in self.comportements else None
yield comportement
示例14: transUvVector
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def transUvVector(self):
max_position = 0.
min_position_x = 0.
min_position_y = 0.
# calculate two rotation matrix from normal vector of selected polygons
vector_nor = self.averageNormal()
theta_x = self.calcRotAngle('X', vector_nor.x, vector_nor.y, vector_nor.z)
mat_rotx = Matrix.Rotation(theta_x, 3, 'X')
vector_nor.rotate(mat_rotx)
theta_y = self.calcRotAngle('Y', vector_nor.x, vector_nor.y, vector_nor.z)
mat_roty = Matrix.Rotation(theta_y, 3, 'Y')
# apply two rotation matrix to vertex
uv_array = self.mesh.uv_layers.active.data
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
new_vector = Vector((self.mesh.vertices[self.mesh.loops[id].vertex_index].co[0],
self.mesh.vertices[self.mesh.loops[id].vertex_index].co[1],
self.mesh.vertices[self.mesh.loops[id].vertex_index].co[2]))
new_vector.rotate(mat_rotx)
new_vector.rotate(mat_roty)
uv_array[id].uv = new_vector.to_2d()
if min_position_x > uv_array[id].uv.x:
min_position_x = uv_array[id].uv.x
if min_position_y > uv_array[id].uv.y:
min_position_y = uv_array[id].uv.y
# recalculate uv position
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
uv_array[id].uv.x = uv_array[id].uv.x + abs(min_position_x)
uv_array[id].uv.y = uv_array[id].uv.y + abs(min_position_y)
if max_position < uv_array[id].uv.x:
max_position = uv_array[id].uv.x
if max_position < uv_array[id].uv.y:
max_position = uv_array[id].uv.y
# scale uv position
for poly in self.select_poly:
for id in range(poly.loop_start, poly.loop_start + poly.loop_total):
uv_array[id].uv.x = uv_array[id].uv.x * MAX_LOCATION / max_position
uv_array[id].uv.y = uv_array[id].uv.y * MAX_LOCATION / max_position
示例15: setupStartPos
# 需要导入模块: from mathutils import Vector [as 别名]
# 或者: from mathutils.Vector import rotate [as 别名]
def setupStartPos(self):
"""Creates the starting position information"""
player = bpy.data.objects["Player"]
viewDir = Vector((0.0, 0.0, -1.0))
viewDir.rotate(player.rotation_euler)
upDir = Vector((0.0, 1.0, 0.0))
upDir.rotate(player.rotation_euler)
start = { }
start['position'] = { 'x': ConvertHelper.convert_pos(player.location.x), 'y': ConvertHelper.convert_pos(player.location.y), 'z': ConvertHelper.convert_pos(player.location.z) }
start['viewDirection'] = { 'x': ConvertHelper.convert_pos(viewDir.x), 'y': ConvertHelper.convert_pos(viewDir.y), 'z': ConvertHelper.convert_pos(viewDir.z) }
start['upDirection'] = { 'x': ConvertHelper.convert_pos(upDir.x), 'y': ConvertHelper.convert_pos(upDir.y), 'z': ConvertHelper.convert_pos(upDir.z) }
return start