-
Notifications
You must be signed in to change notification settings - Fork 5
/
head_rotation.py
77 lines (60 loc) · 2.25 KB
/
head_rotation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import bpy
import bmesh
from mathutils import *; from math import *
import numpy as np
import math
def adjust_point_cloud_loc(face_mesh_list, pin_idx, ignore=None):
''' will change this later'''
new_face_mesh_list = []
for face_mesh in face_mesh_list:
pin_point = face_mesh[pin_idx]
new_face_mesh = []
for idx, vert in enumerate(face_mesh):
if ignore == None:
vert = vert - pin_point # cant do -= here
new_face_mesh.append(vert)
else:
for i in range(len(ignore)):
if idx == ignore[i]:
pass
else:
vert[0] = vert[0] - pin_point[0]
vert[2] = vert[2] - pin_point[2] # cant do -= here
new_face_mesh.append(vert)
new_face_mesh_list.append(new_face_mesh)
return new_face_mesh_list
def rotate_along_axis(verts, axis, main_point_idx, target):
# remove nil axis
verts = np.delete(verts, axis, axis=1)
# caluclate radius of each vert
verts_squared = verts**2
radius = np.sqrt(np.sum(verts_squared, axis=1))
# define main point
mp_radius = radius[main_point_idx]
mp = verts[main_point_idx]
# get angles relative to main point
dot = np.dot(verts, mp)
mag = radius * mp_radius
angle = np.arccos(dot/mag)
# get angles relative to target.
dot = np.dot(verts, target)
mag = radius * target[0]
angles = np.arccos(dot/mag)
# finding out if points are left or right of main point
slope = mp[1] / mp[0]
if mp[0] > 0:
side = np.argwhere(verts[:,1] >= verts[:,0] * slope)
else:
side = np.argwhere(verts[:,1] <= verts[:,0] * slope)
# adjusting angle offset
for i in side:
angle[i] = np.negative(angle[i])
offset = np.radians(90)
angle += offset
angle[main_point_idx] = np.radians(90)
# creating x,y vaules
y = radius * np.cos(angle)
x = radius * np.sin(angle)
verts = np.stack((x,y), axis=1)
# return verts and amount the object was rotated
return verts, angles[main_point_idx]