用blender環繞物體拍攝

2021-10-14 10:13:14 字數 3782 閱讀 5160

相機位置使用球面函式計算。

相機位置 v:

blender中相機座標系

xyz的尤拉角旋轉是繞世界系的xyz旋轉的。

尤拉角計算:

旋轉根據當前相機位置:

θz = acos(y*(x,y,0))

如果x >0

θz = 180-θz

反之θz = θz - 180

θx = acos(z*v)

θy = 恆等於0

def creatcamera(t_location,rotation_euler,scale):

scene = bpy.context.scene

sensor_width_in_mm = k[1]

[1]*k[0]

[2] / (k[0]

[0]*k[1]

[2])

sensor_height_in_mm = 1 # doesn't matter

resolution_x_in_px = k[0]

[2]*2 # principal point assumed at the center

resolution_y_in_px = k[1]

[2]*2 # principal point assumed at the center

s_u = resolution_x_in_px / sensor_width_in_mm

s_v = resolution_y_in_px / sensor_height_in_mm

# todo include aspect ratio

f_in_mm = k[0]

[0] / s_u

# recover original resolution

scene.render.resolution_x = resolution_x_in_px / scale

scene.render.resolution_y = resolution_y_in_px / scale

scene.render.resolution_percentage = scale * 100

# create a new camera

bpy.ops.object.add(

type=

'camera',

location=t_location)

ob = bpy.context.object

ob.name =

'camfrom3x4pobj'

cam = ob.data

cam.name =

'camfrom3x4p'

# lens

cam.type =

'persp'

cam.lens = f_in_mm

cam.lens_unit =

'millimeters'

cam.sensor_width = sensor_width_in_mm

pi = math.pi

ob.rotation_mode =

'xyz'

ob.rotation_euler[0]

= rotation_euler[0] * (pi / 180.0)

ob.rotation_euler[1]

= rotation_euler[1] * (pi / 180.0)

ob.rotation_euler[2]

= rotation_euler[2] * (pi / 180.0)

# display

cam.show_name = true

# make this the current camera

scene.camera = ob

#bpy.context.scene.update()

def getrotationfromlocation(t_location):

v = t_location

y_axis = vector((.0,

1.0,

.0))

z_axis = vector((.0,

.0,1.0))

tempv = vector((t_location[0] , t_location[1] ,

.0))

pi = math.pi

sitaz = tempv.angle(y_axis)

sitaz =

(180.0 * sitaz) / pi

sitax = v.angle(z_axis)

sitax =

(180.0 * sitax) / pi

if(t_location[0]

< 0):

rotation_euler = vector((sitax ,

1.0,sitaz-

180.0

)) else:

rotation_euler = vector((sitax ,

1.0,

180.0

-sitaz))

print(rotation_euler)

return rotation_euler

if __name__ ==

"__main__"

: pi = math.pi

nrows = 5

ncols = 14

weidu_angles =

[30,60,90,120,150]

r = 10.0

pi = math.pi

for j in range(nrows):

weidu = weidu_angles[j] / 180.0 * pi

for i in range(ncols):

jingdu =

(i*360.0/ncols - 180.0) / 180.0 * pi

print(math.sin(weidu))

x = r*math.sin(weidu)*math.cos(jingdu)

y = r*math.sin(weidu)*math.sin(jingdu)

z = r*math.cos(weidu)

k = matrix(

([2666.666748046875 , 0 , 960.0],

[0 , 2666.666748046875 , 540.0],

[0 , 0 , 1]))

t_location = vector((x , y , z))

print(t_location)

#t_location = vector((-13.9922 , -9.63222 , 4.01505))

rotation_euler = getrotationfromlocation(t_location)

#rotation_euler = vector((76.8264 , 0 , -55.3262))

creatcamera(t_location,rotation_euler,1)

結果:

Blender物體跟蹤實戰教程

什麼是blender物體跟蹤?而一般來說,我們無論在after effect cinema4d maya blender等軟體中,預設啟用的跟蹤模式都是攝像頭反求,也即通過畫面中物體移動的透視變化來反推攝影機的位置,所以一般在完成跟蹤計算後,我們會看到物體處於靜止狀態,而攝像頭在不斷地運動。第零步,...

攝像頭拍攝距離 鏡頭引數 物體大小之間的關係

鏡頭透射原理公式 f d h h 其中 f 表示鏡頭的焦距 固焦或變焦,廠家提供引數 單位 mm d 鏡頭與物體之間的距離,單位 m h 鏡頭的靶面尺寸高度 固定可知,一般為 影象感測器 引數,如 1 3 ccd 單位 mm h 鏡頭拍攝現場的高度 一般為被攝物體高度的2倍 單位 m 我們以天地偉業...

C 用矩陣實現物體旋轉

c 中,三種變換矩陣分為三種 縮放,平移,以及旋轉。其中旋轉是三種變化矩陣中最複雜的一種 用數學角度分析 這是實現物體繞x軸旋轉一定角度 這是實現物體繞y軸旋轉一定角度 這是實現物體繞z軸旋轉一定角度 言歸正傳,c 中為我們的矩形運算做出了規則,所以我們只需要寫出matrix4x4這個規定的矩形之後...