Skip to content Skip to sidebar Skip to footer

How to Draw a 3d Plane in Matlab

Introduction into the drawToolbox

The drawToolbox is a collection of MATLAB functions facilitating plotting of unproblematic second/3D geometric objects like vectors, planes or lines. The toolbox was written for the "Numerical algorithms" class to visualize the geometric ideas central to the methods of numerical linear algebra.

Contents

  • Toolbox content
  • 1. drawVector
  • 2. drawPlane
  • 3. drawSpan
  • 4. drawLine
  • 5. drawMesh
  • 6. drawAxes

Toolbox content

There are 6 functions:

  1. drawVector - Plot 2D/3D vector with axes.
  2. drawPlane - Plot 2D/3D airplane.
  3. drawSpan - Draw line(2D)/aeroplane(3D) spanned by one (2d/3D) or two 3D vectors Five.
  4. drawLine - Plot 2nd/3D line.
  5. drawMesh - Plot polygonal 3D mesh.
  6. drawAxes - Draw second/3D axes lines.

You can go the information about those functions in the usual way past typing assistance function, e.g., assistance drawPlane, in the control window. But now, let's take a quick look on their use just following a few unproblematic examples.

one. drawVector

Example in 2d: Let's draw a 2d vector a = [3 1]':

a = [3 i]' figure(one); clf; drawVector(a)        
a =       3      i        

Annotation the coordinate axes. They are added automatically.

As you encounter the default color of a vector is blue and default mark is a dot. Yous tin can easily change it and plot the vector in, say, ruddy colour with a square mark sine.

drawVector(a,          'rs')        

It is also possible to name the vector, specifying its label in curly brackets, as a cell assortment:

drawVector(a,          'rs', {'a'})        

To draw a second vector, e.grand., b = [-2 1]' nosotros tin practice the following:

b = [-two 1]'; concord          on; drawVector(b, {'b'}) concur          off;        

But there is a nicer way to do that in one line:

effigy(one); clf; drawVector([a b],          'thousand>', {'a',          'b'});        

Yet, now you do not have an access to the individual colors and markers of the 2 vectors.

In similar style you can plot more vectors, just put it as columns into a matrix. E.g.:

A = [ 2 iii 1 ;       4 1 ane ]; drawVector(A, {'a',          'b',          'c'});        

or form random matrix (iterate this prison cell several times):

A = rand(2, 10)*2 - ane; drawVector(A,          'go');        

Is information technology clear why there is the multiplication by ii and offset by -one?

Example in 3D: The aforementioned you tin do also in 3D. Let's describe two random 3D vectors: A = rand(3, 2)*two - 1;

A = rand(three, 2)*2 - 1; figure(1); clf; drawVector(A, {'a',          'b'}); view(60,x)        

Again the axes are added automaticaly. If you would similar to take dissimilar axes labels pass them as a cell array with the optional parameter, 'AxesLabels':

A = [ i  1;       ii -2       3  3 ]; effigy(i); clf; drawVector(A, {'a',          'b'},          'AxesLabels', {'\alpha','\beta','\gamma'}); view(threescore,10)        

2. drawPlane

A plane is defined by a normal vector, n, that defines airplane's orientation and a scalar, d, defining the magnitude of a shift of the plane from the origin in the direction of n. For the given n and d, all the points (i.e., vectors x), satisfying the following equations belong to the plane:

With the function drawPlane(), y'all tin hands visualize planes in 2 and ii dimensions. Let's brainstorm with 3D case. Consider the following lawmaking:

n = [i two 3]'; effigy(1); clf; concur          on; drawVector(n, {'north'});        drawPlane(n);                drawPlane(n, 5,          'r');        view(threescore,15) hold          off;        

In 2nd, a aeroplane is a straight line. Beneath, is a like example equally above only in 2nd:

northward = [1 two]'; figure(1); clf; hold          on; drawVector(n, {'n'});        drawPlane(northward);                drawPlane(n, 2,          'r');        hold          off;        

iii. drawSpan

At that place is some other possibility to specify a (hyper-)plane in an N-dimensional infinite: specify Due north-1 ND-vectors that will span the plane, i.east., vectors that lie in the plane. The drawSpan() routine visualizes planes in 2nd and 3D defined in this way.

Example in 3D:

a = [i 2 3]'; b = [one 1 1]';          effigy(1);clf; hold          on; drawVector([a b], {'a','b'}); drawSpan([a b],          'b') view(-40,five) hold          off;        

Note: A aeroplane, divers equally vectors span always contains the origin. To put it in mathematical terms, it is a linear subspace. If you'd like to shift the airplane, yous'll have to compute its normal and use the drawPlane() function:

due north = cross(a,b);                      effigy(1);agree          on; drawVector(n, {'n'},          'r'); drawPlane(n, 4,          'r')                 view(-lx,5) hold          off;        

Example in second: A plane in 2D is defined past a single 2D-vector:

a = [1 1]; figure(1); clf; drawSpan(a);        

4. drawLine

As its name suggests, this function draws a line (2d or 3D) between two points (i.e., vectors). Past default, the line blazon is dashed and its color is black only you can easily modify it. Here is an case:

Example in second:

a = [two 1]'; b = [three -two]';             figure(1);clf; concur          on; drawVector([a b], {'a','b'});        drawLine([a b]);                     concord          off;        

Change the line style (run into help drawLine).

figure(ane);clf; concur          on; drawVector([a b], {'a','b'});        drawLine([a b],          'r2-.');             concord          off;        

Example in 3D:

a = [ane 2 3]'; b = [three -1 two]';         figure(i);clf; hold          on; drawVector([a b], {'a','b'});        drawLine([a b],          'r3');               view(fifteen,5); hold          off;        

5. drawMesh

This function plots a 3D polygonal mesh. A "mesh" is defined by two arrays: V and F. The kickoff 1 has the dimensions n-by-iii and contains the 3D coordinates of n "vertices". The 2d m-by-m array of "faces" defines the connectivity of the vertices: each of the m rows correspond to a face and contains the numbers (i.e., positive integers) of the vertices incident with the face. Different faces can have different number of vertices, k is the maximum number of vertices among all the faces. The next examples analyze the issue:

Example i: Surface plot

load('queen.mat');                   figure(1); clf; drawMesh(vertex, face)               view(twenty, sixty)        

Of grade, yous are free to modify the color of the mesh:

figure(1); clf; drawMesh(vertex, face,          'b')          view(xx, 60)        

... and modify its transparency:

figure(1); clf; drawMesh(vertex, face,          'b', .5)      view(twenty, lx)        

Example two: Wire-frame plot

figure(i); clf; drawMesh(vertex, face,          'wire')       view(twenty, 60)        

6. drawAxes

This is the office that you'll near never employ straight, only which is chosen by nearly all other functions in the toolbox. It plots the "xy" (2nd) or "xyz" (3D) axes lines into the current effigy. It takes 2 mandatory parameters: dimension number, d = {2,3}, and the axes color.

Example in 3D: Staying with the previous example

load('queen.mat');                       figure(1); clf; drawMesh(vertex, face,          'wire'); drawAxes(3,          'grand');                        view(60, x)        

Sometimes yous would similar to have different axes labels instead of standard "xyz". It can be washed with drawAxes supplying it with an additional (optional) parameter, a cell array:

effigy(1); clf; drawMesh(vertex, face,          'wire'); drawAxes(three,          'r', {'Axes 1','Axes two','Axes 3'});  view(60, x)        

Example in 2D:

figure(i); clf; plot(exp(two*pi*i*(1:20)/20),          '.'); drawAxes(2,          'k', {'\alpha','\beta'});        


This ends the introduction. For more data, blazon assistance part . For comments, bugs and suggestions contact: vladimir.bondarenko at uni.konstanz.de.

crichtonhatichoode.blogspot.com

Source: https://cms.uni-konstanz.de/fileadmin/archive/informatik-saupe/fileadmin/informatik/ag-saupe/Webpages/lehre/na_08/Lab1/1_Preliminaries/html/drawToolIntro.html

Post a Comment for "How to Draw a 3d Plane in Matlab"