Draw a Circle of Radius in Matlab
# Cartoon
# Circles
The easiest option to draw a circle, is - apparently - the rectangle
(opens new window) function.
just the curvature of the rectangle has to be prepare to 1!
The position
vector defines the rectangle, the starting time two values ten
and y
are the lower left corner of the rectangle. The final 2 values define width and top of the rectangle.
The lower left corner of the circumvolve - yes, this circle has corners, imaginary ones though - is the center c = [three three]
minus the radius r = 2
which is [x y] = [1 one]
. Width and summit are equal to the diameter of the circle, so width = two*r; height = width;
In case the smoothness of the above solution is non sufficient, there is no way around using the obvious way of cartoon an actual circumvolve by use of trigonometric functions.
# Arrows
Firstly, 1 can use quiver
(opens new window) , where ane doesn't have to deal with unhandy normalized effigy units past use of annotation
Important is the 5th argument of quiver
: 0 which disables an otherwise default scaling, every bit this function is usually used to plot vector fields. (or use the property value pair 'AutoScale','off'
)
One tin also add boosted features:
(opens new window)
If different arrowheads are desired, one needs to use annotations (this answer is may helpful How do I change the pointer head style in quiver plot? (opens new window) ).
The arrow head size tin can be adjust with the 'MaxHeadSize'
property. Information technology's not consequent unfortunately. The axes limits need to be set up after.
At that place is another tweak for adjustable pointer heads: (opens new window)
which you lot can phone call from your script as follows:
# Ellipse
To plot an ellipse you can use its equation (opens new window) . An ellipse has a major and a pocket-sized axis. Besides we want to be able to plot the ellipse on different center points. Therefore we write a office whose inputs and outputs are:
You can use the following role to become the points on an ellipse and and so plot those points.
Exmaple:
(opens new window)
# Polygon(s)
Create vectors to agree the x- and y-locations of vertices, feed these into patch
.
# Single Polygon
(opens new window)
# Multiple Polygons
Each polygon's vertices occupy ane cavalcade of each of Ten
, Y
.
(opens new window)
# Pseudo 4D plot
A (m x n)
matrix tin can exist representes by a surface by using surf (opens new window) ;
The color of the surface is automatically set equally function of the values in the (grand x n)
matrix. If the colormap (opens new window) is not specified, the default one is practical.
A colorbar (opens new window) can be added to brandish the current colormap and indicate the mapping of data values into the colormap.
In the following example, the z (1000 ten due north)
matrix is generated by the office:
over the interval [-pi,pi]
. The 10
and y
values tin can exist generated using the meshgrid (opens new window) role and the surface is rendered as follows:
(opens new window)
Figure one
Now it could be the example that boosted information are linked to the values of the z
matrix and they are store in another (m ten n)
matrix
It is possible to add these boosted information on the plot by modifying the mode the surface is colored.
This volition allows having kinda of 4D plot: to the 3D representation of the surface generated past the first (m ten due north)
matrix, the time will be represented by the data contained in the second (m x north)
matrix.
It is possible to create such a plot by calling surf
with 4 input:
where the C
parameter is the second matrix (which has to exist of the aforementioned size of z
) and is used to define the color of the surface.
In the following instance, the C
matrix is generated by the function:
over the interval [-pi,pi]
The surface generated by C
is
(opens new window)
Figure ii
Now we can call surf
with four input:
(opens new window)
Effigy 3
Comparing Figure 1 and Figure three, we can notice that:
- the shape of the surface corresponds to the
z
values (the first(grand x n)
matrix) - the colour of the surface (and its range, given by the colorbar) corresponds to the
C
values (the first(m x n)
matrix)
(opens new window)
Figure 4
Of course, information technology is possible to bandy z
and C
in the plot to have the shape of the surface given by the C
matrix and the color given by the z
matrix:
and to compare Effigy 2 with Effigy 4
(opens new window)
# Fast drawing
At that place are iii chief ways to do sequential plot or animations: plot(x,y)
, prepare(h , 'XData' , y, 'YData' , y)
and animatedline
. If y'all want your animation to be shine, you need efficient drawing, and the iii methods are not equivalent.
I get 5.278172 seconds
. The plot function basically deletes and recreates the line object each fourth dimension. A more efficient way to update a plot is to use the XData
and YData
backdrop of the Line
object.
Now I get ii.741996 seconds
, much ameliorate!
animatedline
is a relatively new role, introduced in 2014b. Let's see how it fares:
three.360569 seconds
, not every bit good every bit updating an existing plot, but still improve than plot(x,y)
.
Of course, if you have to plot a single line, like in this example, the iii methods are almost equivalent and requite smooth animations. Merely if you have more circuitous plots, updating existing Line
objects will brand a difference.
Source: https://devtut.github.io/matlab/drawing.html
Publicar un comentario for "Draw a Circle of Radius in Matlab"