Draw a Circle With Matlab
# Cartoon
# Circles
The easiest option to draw a circle, is - obviously - the rectangle
(opens new window) function.
but the curvature of the rectangle has to be prepare to ane!
The position
vector defines the rectangle, the first two values 10
and y
are the lower left corner of the rectangle. The last two values ascertain width and top of the rectangle.
The lower left corner of the circle - yep, this circle has corners, imaginary ones though - is the centre c = [three 3]
minus the radius r = ii
which is [ten y] = [ane one]
. Width and pinnacle are equal to the diameter of the circumvolve, so width = two*r; height = width;
In instance the smoothness of the above solution is not sufficient, there is no way around using the obvious style of drawing an actual circle by utilise of trigonometric functions.
# Arrows
Firstly, i can use quiver
(opens new window) , where i doesn't have to bargain with unhandy normalized effigy units by employ of annotation
Of import is the 5th argument of quiver
: 0 which disables an otherwise default scaling, as this part is usually used to plot vector fields. (or utilise the property value pair 'AutoScale','off'
)
One tin also add boosted features:
(opens new window)
If unlike arrowheads are desired, 1 needs to utilise annotations (this answer is may helpful How do I change the arrow head style in quiver plot? (opens new window) ).
The arrow head size can be adjust with the 'MaxHeadSize'
holding. It's not consequent unfortunately. The axes limits need to exist set afterward.
There is another tweak for adjustable arrow heads: (opens new window)
which you tin can call from your script as follows:
# Ellipse
To plot an ellipse yous tin can use its equation (opens new window) . An ellipse has a major and a minor axis. Besides nosotros want to be able to plot the ellipse on different centre points. Therefore we write a function whose inputs and outputs are:
You tin employ the following function to get the points on an ellipse then plot those points.
Exmaple:
(opens new window)
# Polygon(s)
Create vectors to agree the x- and y-locations of vertices, feed these into patch
.
# Unmarried Polygon
(opens new window)
# Multiple Polygons
Each polygon'due south vertices occupy 1 cavalcade of each of X
, Y
.
(opens new window)
# Pseudo 4D plot
A (chiliad x northward)
matrix tin be representes past a surface by using surf (opens new window) ;
The color of the surface is automatically gear up as function of the values in the (m x n)
matrix. If the colormap (opens new window) is not specified, the default one is applied.
A colorbar (opens new window) tin can exist added to display the current colormap and indicate the mapping of data values into the colormap.
In the following example, the z (m x due north)
matrix is generated by the function:
over the interval [-pi,pi]
. The 10
and y
values can be generated using the meshgrid (opens new window) role and the surface is rendered as follows:
(opens new window)
Figure 1
Now information technology could be the example that additional information are linked to the values of the z
matrix and they are store in some other (k x n)
matrix
Information technology is possible to add together these boosted information on the plot by modifying the mode the surface is colored.
This will allows having kinda of 4D plot: to the 3D representation of the surface generated by the outset (1000 x n)
matrix, the quaternary dimension will be represented by the information contained in the second (grand 10 north)
matrix.
It is possible to create such a plot past calling surf
with 4 input:
where the C
parameter is the second matrix (which has to be of the same size of z
) and is used to ascertain the color of the surface.
In the following case, the C
matrix is generated by the office:
over the interval [-pi,pi]
The surface generated by C
is
(opens new window)
Figure 2
Now nosotros can call surf
with four input:
(opens new window)
Figure 3
Comparison Figure i and Figure iii, nosotros can notice that:
- the shape of the surface corresponds to the
z
values (the commencement(m x n)
matrix) - the colour of the surface (and its range, given past the colorbar) corresponds to the
C
values (the first(m x due north)
matrix)
(opens new window)
Figure 4
Of grade, information technology is possible to swap z
and C
in the plot to have the shape of the surface given by the C
matrix and the colour given by the z
matrix:
and to compare Effigy 2 with Figure 4
(opens new window)
# Fast drawing
There are three main ways to practise sequential plot or animations: plot(ten,y)
, set(h , 'XData' , y, 'YData' , y)
and animatedline
. If you want your blitheness to exist shine, y'all demand efficient cartoon, and the three methods are non equivalent.
I get 5.278172 seconds
. The plot role basically deletes and recreates the line object each time. A more efficient way to update a plot is to use the XData
and YData
properties of the Line
object.
Now I get 2.741996 seconds
, much better!
animatedline
is a relatively new role, introduced in 2014b. Let'southward see how it fares:
3.360569 seconds
, not as skilful as updating an existing plot, only still ameliorate than plot(x,y)
.
Of grade, if you have to plot a single line, similar in this case, the iii methods are nigh equivalent and give smooth animations. Only if you lot have more complex plots, updating existing Line
objects will make a divergence.
Source: https://devtut.github.io/matlab/drawing.html
0 Response to "Draw a Circle With Matlab"
Post a Comment