How to Use Two Vectors to Draw a Plane Matlab
Lines, Planes and MATLAB
copyright 2009 by Jonathan Rosenberg based on an earlier spider web page, copyright 2000 by Paul Light-green and Jonathan Rosenberg
Contents
- Example 1:
- Example 2:
- Example 3:
- Example iv:
- Problem one:
- Problem 2:
In this published M-file, we will use MATLAB to solve bug most lines and planes in three-dimensional space. The mathematical content corresponds to chapter eleven of the text by Gulick and Ellis.
We brainstorm with the problem of finding the equation of a plane through three points.
Case 1:
Find an equation for the plane through the points (i,-one,three), (2,3,iv), and (-five,half-dozen,vii).
We begin by creating MATLAB arrays that represent the iii points:
P1 = [ane,-one,3]; P2 = [2,3,four]; P3 = [-5,6,vii];
If you wish to run into MATLAB'due south response to these commands, you should delete the semicolons. Next, we create the normal vector to our aeroplane by taking the cross-product of two vectors parallel to the airplane.
normal = cross(P1-P2, P1-P3)
normal = ix -10 31
Next, nosotros declare ten, y, and z to be symbolic variables, create a vector whose components represent the vector from P1 to a typical indicate on the aeroplane, and compute the dot production of this vector with our normal.
syms x y z P = [ten,y,z] planefunction = dot(normal, P-P1)
P = [ ten, y, z] planefunction = 9*x - 10*y + 31*z - 112
The equation of our aeroplane is now planefunction = 0. Nosotros remark that the MATLAB's symbolic dot product assumes that the its arguments may be complex and takes the circuitous conjugates of the components of its first argument. To come across the consequence of this, we compute instead:
dot(P-P1, normal)
ans = 9*conj(x) - 10*conj(y) + 31*conj(z) - 112
Since in this course nosotros merely want dot products of real-valued vectors, it helps instead to ascertain
realdot = @(u, v) u*transpose(v);
to avoid this annoyance.
realdot(P-P1,normal)
ans = 9*x - 10*y + 31*z - 112
Example two:
Permit usa now apply the equation of the plane in Case 1 to notice the point of intersection of the airplane with the line through (i,2,-one) and (iii,3,three).
P4 = [1,2,-1]; P5 = [3,3,iii];
We parametrize the line:
syms t line = P4 + t*(P5-P4)
line = [ ii*t + one, t + 2, 4*t - one]
line now gives the coordinates of a typical point on our line in terms of the parameter t. Nosotros can now evaluate planefunction at such a point by substituting line for P.
newfunction = subs(planefunction, P, line)
newfunction = 132*t - 154
Now we solve newfunction = 0 for t, and substitute the outcome in line to obtain our desired point, and cheque our answer.
t0 = solve(newfunction) point = subs(line, t, t0) subs(planefunction, P, point)
t0 = vii/six signal = [ ten/3, 19/6, 11/3] ans = 0
Notice that the command solve(newfunction) automatically sets the function to nada, recognizes the contained variable, and solves for information technology.
Example 3:
Let u.s. now utilize the plotting capabilities of MATLAB to plot the aeroplane and the line. First we solve for z in terms of ten and y in the equation of the plane.
zplane = solve(planefunction, z)
zplane = (10*y)/31 - (9*x)/31 + 112/31
We will at present plot our plane and our already parametrized line on the same set of axes. Nosotros will use the command concur on to put both plots on the same diagram.
ezplot3(line(1), line(2), line(3), [-1,three]), concord on ezmesh(zplane, [2, viii, two, 8]), hold off axis([2, 8, 2, 8, 0, 6]), title ''
We should point out that doing things this manner with ezmesh and ezplot3 , it's necessary to plot first the line and and then the plane. The reason is that the code for ezplot3 is written in such a way as to disengage the event of any previously issued concur on command. Of course one can get around this by using plot3 instead of ezplot3 , like this:
ezmesh(zplane, [two, viii, two, 8]), hold on tt = -1:3; linex = subs(line(ane), t, tt); liney = subs(line(2), t, tt); linez = subs(line(three), t, tt); plot3(linex, liney, linez), agree off centrality([2, 8, 2, 8, 0, 6]), title ''
But manifestly this is more bad-mannered.
Case four:
Let us now see if we can observe an equation for the cylinder of radius 3 effectually our line (Compare Gulick and Ellis Department 11.v Problem 26). The cylinder in question is the ready of all points whose distance from the line is four. P already represents a generic point with coordinates (ten,y,z) and line represents a bespeak on the line. Thus the square of the distance from a point in infinite to a point on the line is given by
distsq = realdot(P-line, P-line)
distsq = (t - y + ii)^2 + (z - iv*t + 1)^ii + (two*t - ten + i)^2
What we want to exercise is to minimize this squared altitude as a part of t, while keeping x, y, and z generic.
distsqprime = diff(distsq, t) tcrit = solve(distsqprime, t) distsqfunc = simplify(subs(distsq, t, tcrit)) cylinder = distsqfunc - ix
distsqprime = 42*t - 4*10 - 2*y - eight*z tcrit = (2*x)/21 + y/21 + (4*z)/21 distsqfunc = ((8*x)/21 + (4*y)/21 - (v*z)/21 - 1)^two + ((ii*ten)/21 - (twenty*y)/21 + (4*z)/21 + 2)^two + ((two*y)/21 - (17*x)/21 + (8*z)/21 + one)^2 cylinder = ((eight*10)/21 + (4*y)/21 - (5*z)/21 - 1)^2 + ((2*x)/21 - (20*y)/21 + (4*z)/21 + two)^two + ((2*y)/21 - (17*ten)/21 + (8*z)/21 + one)^2 - 9
Setting the concluding output to 0 gives united states of america a function for the cylinder.
Problem 1:
In this problem you lot volition find the distance from bespeak P4 to the plane of Example 1 3 different ways:
- (a) By using the method of Section xi.six of Gulick and Ellis, performing the calculations with MATLAB.
- (b) By finding the foot of the perpendicular from P4 to the plane as follows:
- Parametrize the line through P4 normal to the aeroplane.
- Observe the bespeak mutual to the line you have just parametrized and the plane, as in Instance 2.
- Find the altitude between the bespeak you have but found and P4.
Verify that methods a) and b) requite the same answer.
- (c) By parametrizing the plane and minimizing the square of the distance from a typical betoken on the plane to P4. Parametrize the airplane in the grade P1+due south(P2-P1)+t(P3-P1). As in Instance 4, find and proper noun the distance from P4 to a typical bespeak on the plane. Still every bit in Example 4, but retaining s as a parameter, minimize the foursquare of the altitude with respect to t. The result should nonetheless comprise the parameter s. And then minimize the event with respect to south.
Problem ii:
Find the equation of the plane in Example 1 in another way, by bold that the equation has the form ax + by + cz = ane (this is always possible if the plane doesn't go through the origin), and solving for a, b and c and so as to brand the plane pass through P1, P2, and P3. Check that your answer agrees with the i we plant to a higher place.
Source: http://www2.math.umd.edu/~jmr/241/lines_planes.html
0 Response to "How to Use Two Vectors to Draw a Plane Matlab"
Post a Comment