Skip to Main Content Skip to Search
Product Documentation

plot::Polygon2d2D polygons

plot::Polygon3d3D polygons

plot::Polygon2d, plot::Polygon3d define polygons in 2D and 3D, respectively, by a given list of vertex points.

→ Examples

Calls:

plot::Polygon2d([pt2d1, pt2d2, ...], <a = amin .. amax>, Options)

plot::Polygon3d([pt3d1, pt3d2, ...], <a = amin .. amax>, Options)

plot::Polygon2d(`M_{2d}`, <a = amin .. amax>, Options)

plot::Polygon3d(`M_{3d}`, <a = amin .. amax>, Options)

Parameters:

pt2d1, pt2d2, ...: 

the 2D vertices. These must not be of type plot::Point2d, but lists of two numerical real values or arithmetical expressions of the animation parameter a (the coordinates). 
pt2d1, pt2d2, ... is equivalent to the attribute Points2d.

pt3d1, pt3d2, ...: 

the 3D vertices. These must not be of type plot::Point3d, but lists of three numerical real values or arithmetical expressions of the animation parameter a (the coordinates).     
pt3d1, pt3d2, ... is equivalent to the attribute Points3d.

`M_{2d}`

an array or a matrix with 2 columns. Each row provides the coordinates of one point.   
`M_{2d}` is equivalent to the attribute Points2d.

`M_{3d}`

an array or a matrix with 3 columns. Each row provides the coordinates of one point.   
`M_{3d}` is equivalent to the attribute Points3d.

See Also:

plot, plot::copy, plot::Line2d, plot::Line3d, plot::Listplot

Details:

Example 1

We create a polygon with vertices located at the 5 complex 5^th roots of 1. The polygon consists of the 4 lines joining the 5 points in the order given:

p := plot::Polygon2d(
       [[cos(2*PI*k/5), sin(2*PI*k/5)] $ k = 0..4]):
plot(p, plot::Circle2d(1, [0, 0])):

MuPAD graphics

In order to include the line connecting the last with the first point, pass the attribute Closed to the polygon:

p::Closed := TRUE:
plot(p, plot::Circle2d(1, [0, 0])):

MuPAD graphics

delete p

Example 2

We plot a closed star-shaped 3D polygon with various color attributes:

p := plot::Polygon3d(
       [([cos(PI*k/3), sin(PI*k/3), sin(PI*k/3)],
         [cos(PI*k/3 + PI/6)/2,
          sin(PI*k/3 + PI/6)/2,
          sin(PI*k/3 + PI/6)/2]) $k = 1..6
       ], Closed = TRUE):
S1 := plot::Scene3d(p, LineColorType = Flat):
S2 := plot::Scene3d(p, LineColorType = Dichromatic):
S3 := plot::Scene3d(p, LineColorType = Dichromatic,
                    LineColor = RGB::Blue,
                    LineColor2 = RGB::Green):
S4 := plot::Scene3d(p, LineColorType = Rainbow,
                    LineColor = RGB::Blue,
                    LineColor2 = RGB::Green):
plot(S1, S2, S3, S4)

MuPAD graphics

We plot the same polygon while animating its line color using a color function. The result is a dazzling star:

p := plot::Polygon3d(
       [([cos(PI*k/3), sin(PI*k/3), sin(PI*k/3)],
         [cos(PI*k/3 + PI/6)/2,
          sin(PI*k/3 + PI/6)/2,
          sin(PI*k/3 + PI/6)/2]) $k = 1..6
       ], Closed = TRUE,
       LineColorFunction =
           proc(x, y, z, i, a) begin
             [sin(x + a*i)^2, sin(y + a*i)^2, sin(z + a*i)^2]:
           end_proc,
       a = 0..10):
plot(p)

MuPAD graphicsimage

delete p, S1, S2, S3, S4

Example 3

We plot a closed 2D polygon and fill the area inside. In fact, there are two possible interpretations of what “inside” really means. In the first plot, the complement of the unbound component of the complement of the polygon is filled. In the second plot only that area is filled that contains points with non-zero winding number with respect to the polygon. Cf. FillStyle for a detailed discussion.

p := plot::Polygon2d(
      [[cos(PI*k/3), sin(PI*k/3)] $k = 1..6,
       [cos(PI*k/3 + PI/6)/2, sin(PI*k/3 + PI/6)/2] $k = 1..6
      ], Closed = TRUE):
S1 := plot::Scene2d(p, Filled = TRUE):
S2 := plot::Scene2d(p, Filled = TRUE, FillStyle = Winding):
plot(S1, S2, Layout = Horizontal, Axes = Frame,
     Scaling = Constrained)

MuPAD graphics

delete p, S1, S2:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS