I wrote a Python script that parametrized the location and rotation of the camera using a random generator.
import bpy
import random
bpy.data.scenes["Scene"].frame_current = 0
for i in range(100):
# Set the current frame
bpy.context.scene.frame_set(i)
# move with camera
# location
location_x = random.uniform(-0.25, 0.25)
location_y = random.uniform(-0.15, 0.15)
location_z = random.uniform(2.8, 3.8)
bpy.data.objects["Camera"].location[0] = location_x
bpy.data.objects["Camera"].location[1] = location_y
bpy.data.objects["Camera"].location[2] = location_z
# rotation
random_x = random.uniform(-0.0523599, 0.0523599)
random_y = random.uniform(-0.10472, 0.10472)
random_z = random.uniform(-0.20944, 0.20944)
bpy.data.objects["Camera"].rotation_euler[0] = random_x
bpy.data.objects["Camera"].rotation_euler[1] = random_y
bpy.data.objects["Camera"].rotation_euler[2] = random_z
#-----------Setup animation------------------
bpy.data.objects["Camera"].keyframe_insert(data_path="location", frame=i)
bpy.data.objects["Camera"].keyframe_insert(data_path="rotation_euler", frame=i)
The camera render should capture the ID card (gray rectangle) as you can see in the image below. However, sometimes part of the ID card is missing. Typically one corner is missing.
Can I somehow check if the whole ID card will be in the rendered image?
I tried approaches such as the camera's view frustum in world space, and converting ID card coordinates to world space to check if the coordinates are inside the rectangle. I think I was close to solving the problem, but it didn't work.
Here is my blend file: https://en.webshare.cz/#/file/KJpPypF1p4/id-card-blend. You can run animation and see different frames. Please, do you have any suggestions?

pythontag when asking python questions... I'm filtering questions by tags and maybe others do that, too. – Gordon Brinkmann Oct 25 '23 at 10:28