Skip to main content
added "automatic" setting of h and w., fixed formatting
Source Link
quellenform
  • 39.5k
  • 10
  • 56
  • 149
camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens

# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
    # the sensor height is fixed (sensor fit is horizontal), 
    # the sensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
    w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the sensor width is fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens

# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
    # the sensor height is fixed (sensor fit is horizontal), 
    # the sensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
    w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the sensor width is fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens

# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
    # the sensor height is fixed (sensor fit is horizontal), 
    # the sensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
    w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the sensor width is fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens

# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
    # the sensor height is fixed (sensor fit is horizontal), 
    # the sensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
    w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the sensor width is fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space. Optionally one could set p = bpy.context.scene.cursor.location in order to locate a 3D point in the scene with the cursor and check its pixel (x,y) location in the rendered image.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens
w
# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_widthsensor_fit == 'VERTICAL':
h =   # the sensor height is fixed (3/4sensor fit is horizontal), * 
 w   # Dependsthe onsensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
 For some reason Iw don't= getpixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the correctsensor valuewidth fromis fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_heightsensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens
w = camera.sensor_width
h = (3/4) * w # Depends on aspect ratio. For some reason I don't get the correct value from camera.sensor_height

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space. Optionally one could set p = bpy.context.scene.cursor.location in order to locate a 3D point in the scene with the cursor and check its pixel (x,y) location in the rendered image.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens

# based on exaplanations in https://blender.stackexchange.com/a/38210 and https://docs.blender.org/manual/en/latest/render/cameras.html#camera
pixel_aspect_ratio =  bpy.context.scene.render.resolution_x / bpy.context.scene.render.resolution_y
if camera.sensor_fit == 'VERTICAL':
    # the sensor height is fixed (sensor fit is horizontal),  
    # the sensor width is effectively changed with the pixel aspect ratio
    h = camera.sensor_height
    w = pixel_aspect_ratio * h
else: # 'HORIZONTAL' and 'AUTO'
    # the sensor width is fixed (sensor fit is horizontal), 
    # the sensor height is effectively changed with the pixel aspect ratio
    w = camera.sensor_width
    h = w / pixel_aspect_ratio

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
typo
Source Link

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens
w = camera.sensor_width
h = (3/4) * w # Depends on aspect ratio. For some reason I don't get the correct value from camera.sensor_height

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h *+ 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens
w = camera.sensor_width
h = (3/4) * w # Depends on aspect ratio. For some reason I don't get the correct value from camera.sensor_height

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h * 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y

I needed to do this recently. I think the following code should do the trick.

p is our point in 3D space.

camera = bpy.data.cameras["Camera"]
scene = bpy.context.scene

f = camera.cycles.fisheye_lens
w = camera.sensor_width
h = (3/4) * w # Depends on aspect ratio. For some reason I don't get the correct value from camera.sensor_height

camera_ob = bpy.data.objects["Camera"]

p = camera_ob.matrix_world.inverted() * p
p.normalize()

# Calculate our angles
phi = math.atan2(p.y, p.x)
l = (p.x**2 + p.y**2)**(1/2)
theta = math.asin(l)

# Equisolid projection
r = 2.0 * f * math.sin(theta / 2)

u = r * math.cos(phi) / w + 0.5
v = r * math.sin(phi) / h + 0.5

x = u * scene.render.resolution_x
y = v * scene.render.resolution_y
Source Link
Loading