Last active
September 15, 2016 19:36
-
-
Save jirihnidek/281be70339535ea8b27adde96be9efc6 to your computer and use it in GitHub Desktop.
Simple Blender script for computing distance between plane (camera) and point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Demonstration of computation distance point to plane. Plane is represented by normal | |
vector and point laying at the plane. | |
""" | |
import bpy | |
import mathutils | |
def main(): | |
""" | |
Example of distance_point_to_plane | |
""" | |
# Get active camera object | |
cam = bpy.context.scene.camera | |
# Get rotation of camera | |
cam.rotation_mode = 'QUATERNION' | |
quat = cam.rotation_quaternion | |
# Blender camera looks to scene in -Z direction | |
norm_vec = quat.to_matrix() * mathutils.Vector((0, 0, -1)) | |
# Get vector representing camera location | |
cam_loc = cam.location | |
# Set position of some testing point | |
point = mathutils.Vector((1.0, 1.0, 1.0)) | |
# Compute distance between point and plane of camera | |
distance = mathutils.geometry.distance_point_to_plane(point, cam_loc, norm_vec) | |
return distance | |
if __name__ == '__main__': | |
print(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment