banner



How To Draw Polygon In Matlab

3D Polygon - describe planes with Matlab

In this example we're going to explain how to describe a 3D polygon using Matlab. More specifically, we are going to describe several apartment surfaces (planes) to build or model a box.

Our principal built-in function in this case is the function "fill3", which is intended to color 3D flat planes.

The sentence fill3(x, y, z, c) would make full the 3D polygon defined by vectors ten, y and z with the colour specified past c. The vertices of the polygon are specified by coordinates of components of 10, y and z, and the polygon is airtight by connecting the final vertex to the first one.

Let'south say that we want to draw this arbitrary rectangular box

Drawing a 3D polygon with Matlab

The coordinates of the eight vertices are every bit follows:

P1(0, 0, 0)
P2(two, 0, 0)
P3(two, 4, 0)
Piv(0, 4, 0)
Pv(0, 0, 3)
P6(ii, 0, 3)
P7(2, iv, 3)
P8(0, iv, 3)

We could draw our first flat surface past filling the area divers past the first iv points, similar this:


p1 = [0 0 0];
p2 = [2 0 0];
p3 = [2 4 0];
p4 = [0 4 0];

ten = [p1(1) p2(1) p3(1) p4(1)];
y = [p1(2) p2(two) p3(2) p4(ii)];
z = [p1(3) p2(three) p3(three) p4(3)];

fill3(x, y, z, i);
xlabel(
'x' ); ylabel( 'y' ); zlabel( 'z' );

The code produces this figure:

First plane of the 3D polygon

Nosotros can expand our axes, add a grid and concur the epitome in order to add together more planes...

axis([-1 3 -1 5 -1 4])
grid
hold
on

produces...

plane drawn with Matlab. Axex expanded.

We tin draw a second surface or aeroplane defined past the concluding 4 vertices:


p5 = [0 0 3];
p6 = [2 0 3];
p7 = [ii 4 3];
p8 = [0 4 3];


ten = [p5(1) p6(1) p7(ane) p8(i)];
y = [p5(ii) p6(2) p7(2) p8(2)];
z = [p5(3) p6(3) p7(3) p8(3)];
fill3(x, y, z, 2);

And the result now is:

Parallel surfaces for our box in Matlab.

We can add together more than surfaces by connecting the appropriate vertices, in the right social club. If nosotros go on our code in a higher place with

ten = [p2(1) p6(1) p7(1) p3(ane)];
y = [p2(2) p6(2) p7(ii) p3(two)];
z = [p2(three) p6(3) p7(3) p3(3)];
fill3(x, y, z, three);

x = [p2(ane) p6(1) p5(1) p1(1)];
y = [p2(2) p6(2) p5(2) p1(ii)];
z = [p2(3) p6(3) p5(3) p1(3)];
fill3(x, y, z, 4);

The resulting 3D-prototype is the following effigy:

4 faces of the box. 3D images


Nosotros can produce or generate different views of the aforementioned 3D-image, of grade:

view(120, 50)

a different view of our 3D polygon


Naturally, we can take a custom-made part to describe rectangles. For instance, save something like this:

function poly_rectangle(p1, p2, p3, p4)
% The points must be in the correct sequence.
% The coordinates must consider 10, y and z-axes.

ten = [p1(1) p2(1) p3(1) p4(1)];
y = [p1(2) p2(ii) p3(2) p4(two)];
z = [p1(3) p2(iii) p3(three) p4(3)];
fill3(x, y, z, rand(size(p1)));
hold on

We can call that function from whatsoever other script or from the control window.

Let's try it:

poly_rectangle(p3, p4, p8, p7)
poly_rectangle(p1, p4, p8, p5)
view(-155, 43)

What did yous get?

From '3D Polygon' to Matlab home

From '3D Polygon' to 3D figures

footer for 3d polygon page

Source: https://www.matrixlab-examples.com/3d-polygon.html

Posted by: jenkinswassely.blogspot.com

0 Response to "How To Draw Polygon In Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel