# How objects move in rendered image when camera position changes

Imagine we render a scene which contains some objects. Now we move camera 1 unit down (no changes in objects) and render a new image. It's obvious that objects would look a little upward in second image (specially objects which are closer to the camera).

My problem is to calculate that how much each object relocates in rendered image based on amount of camera motion and the z-index (depth) of each object. For example camera has moved 1 unit and object A with z-index=4 has moved 15 pixels upward and object B with z-index=10 moved 5 pixels.

So we have depth of each object and amount of camera motion so mathematically it can be calculated, but my main problem is the relation between the measurement system in blender and pixels in rendered image.

So if anyone can give me any idea about this problem I'm dealing with, I would be thankful.

Actually, this is a mathematical question and belongs to math.se.

Moving the camera "down" would be the same as moving the object(s) up. I'll move the object up for illustrative purposes.

For the calculation, you need the focal length and the sensor height of the camera. They are marked lime in the image. You can get that information from the camera. I've set the sensor measurement to vertical. If it is set to horizontal, you would have to calculate the vertical sensor height from the horizontal sensor height and the dimensions.

verticalSensor = horizontalSensor / horizontalDimension * verticalDimension


Next you need the distance from the camera to the object. It is important that the distance vector is an extension of (0, 0, 1) from the camera. The vertical movement is labeled as Object Shift. This vector must be an extension of (0, 1, 0) in camera space for your case. (If the first position of the object is not on the vertically centered horizontal axis of the cameras view space, you have to adjust the calculations.) With the rule of proportion, we can get the relation between these four values.

sensorSpaceMovement / focalLength = objectShift / objectDistance
sensorSpaceMovement = objectShift / objectDistance * focalLength


To get the sensorSpaceMovement (the shift on the sensor) in relation to it's size, we divide by half the sensor's height. (Note, that the lime arrow is half the image's height in the illustration.)

sensorSpaceMovementRelative = objectShift / objectDistance * focalLength / sensorHeight


The objects shift is now relativ to the sensor size and will have a value in [0.0, 1.0] if it doesn't leave the field of view.

To get this value in pixels, multiply it with the number of vertical pixel rows: dimensionY. This is the height of your rendered image.

pixelShift = objectShift / objectDistance * focalLength / sensorHeight * dimensionY


If the relation is rotated in 2D or 3D space, you'll have to use a little more math. The object shift has to be measured relative to the camera's XY plane and the objects distance parallel to the cameras (0, 0, 1) view vector. • Thanks a lot !! Sorry for responding a little late. Actually I was adjusting your solution with my own case and finally it worked great. The relation between focal length, sensor height, object shift and object distance was the key that I needed. Thanks again. – Erfan Samieyan Dec 12 '18 at 20:19