Module 4 Programming - Matlab: 1 Written Exercises
Module 4 Programming - Matlab: 1 Written Exercises
Module 4 Programming - Matlab: 1 Written Exercises
E. Wyatt Anderson
December 14, 2007
1 Written Exercises
1.1 Exercises 1, 2 and 3
For the sake of simplicity in future use of the equations, I formulated the appropriate ex-
pressions while taking f into account at all steps. Using the properties of similar triangles,
we can construct equations for the position of the virtual image of the point P = [XY Z]T on
the virtual image plane, f away from the focal plane xy as follows (The z coordinate of the
xl,r points on the virtual image plane is f , and θ is the angle of the inner triangles formed
by the rays through the image plane):
xr = b − f tan θ
b−X
= b − f tan arctan
Z
b−X
= b−f
Z
xl = −b − f tan θ
−b − X
= −b − f tan arctan
Z
−b − X
= −b − f
Z
Y
yl = yr = f ∗( )
Z
Since we have two cameras, we can use the similar properties of similar triangles to create
inverse expressions given xl , xr , yl , yr , f and b for the point P = [XY Z]T . We effectively create
equations for the lines running from the focal plane through the virtual image plane on the
xz axis, then set them equal to each other to find the intersection, which is the point P :
b(xl + xr )
x =
2b + xl − xr
−f
z = (x − xl ) +f
−b − xl
yl ∗ z
y =
f
1
To test these equations, I first generated MATLAB functions fproject and iproject
for the forward and inverse projections of a point, respectively (these functions are included
in respectively named .m files). For example:
>> P
P =
200
5
6
>> [xl, xr, yl, yr] = fproject(P, 1, 1)
xl =
32.5000
xr =
34.1667
yl =
0.8333
yr =
0.8333
>> iproject(xl, xr, yl, yr, 1, 1)
x =
200.0000
z =
6.0000
y =
5.0000
ans =
200.0000
>>
matrix, with three rows (X , Y , and Z coordinates), with each column representing one point,
as in the MyBox example, which we will use to generate the upcoming figures in this section.
This function performs coordinate transformation, unit conversion, and rendering tasks,
by taking the input model and then applying the appropriate X , Y , and Z translations from
h iT
the X Y Z translation matrix, then it converts the units from millimeters to pixels
based on the specified CCD size, which in this case is equal to .5in. Once the points are
all projected using calls to fproject in fproject.m, the points are all plotted, using the o
marker for the ”right” camera and the + marker for the ”left” camera.
The results of changing the length of f , as shown in Figure 1, are commensurate with
what we would expect given a real camera. The results of panning, tilting, and translating
the camera positions, as shown in Figure 2, are also what we would expect. To translate,
we simply apply the translation amount to the point before we project it. To tilt and pan,
2
0 0 0
50 50 50
0 100 200 300 400 500 600 0 100 200 300 400 500 600 0 100 200 300 400 500 600
0 0 0
50 50 50
0 100 200 300 400 500 600 0 100 200 300 400 500 600 0 100 200 300 400 500 600
50 50
100 100
150 150
200 200
250 250
300 300
350 350
400 400
450 450
0 100 200 300 400 500 600 0 100 200 300 400 500 600
3
we use the product of two transformation matrices defined in move.m and apply them to the
point P that we pass to fproject.
3 Control Simulation
I started to build the control simulation by building the functionality in the .m files Controller.m,
Simulate.m, Camera.m and getconfig.m. Controller.m was destined to be the PID con-
troller as per the assignment, Simulate.m was destined to be the driver for the control
simulation, Camera.m is a functional representation of a camera that can return projected
x, y points in pixels based on the configuration data and a passed point in 3D space P , and
getconfig.m is a simple function for storing configuration variables and returning them
based on a passed key.
Unfortunately, I’ve been unable to get the simulation to a working state. I built up the
appropriate functions to the point where Simulate() should plot a graph of the tilt error,
but given any variation of the P gain, other variables, image size, or the algorithms, the
results are incongruous with what I would expect. I’ve tried a multitude of combinations
in all of my .m files to see if I could get the simulation to behave, but, alas, the clock has
run out. I’m sure with more background in control theory, linear algebra, or MATLAB
programming I could have formulated an appropriate solution to the problem, but with the
skills I have now and what I’ve been able to pick up in this limited amount of time for this
module, I’m currently unable to continue.