Engee documentation
Notebook

Conclusion of graphs in polar coordinate system

In this example, we will show how to output a polar coordinate system graph for the Engee dynamic model.

Polar chart in the interactive script

Graphs in the polar coordinate system allow you to see interrelationships that are not visible on graphs in the rectangular (Cartesian) coordinate system: to get an idea of the expression of some process in certain directions in space, or to trace the recurring dynamics within some cyclic process...

If the work is done in the interactive script Engee, the translation of the graph into the polar coordinate system is done using the argument proj. Its value :polar allows us to plot the chart in polar coordinates:

In [ ]:
Θ = range( 0, stop = 1.5π, length = 100 )
r = abs.( 0.1 * randn(100) + sin.(3Θ) )
plot( Θ, r, proj = :polar, m = 2 )
Out[0]:

Whereas the parameter ortho plots the graph in a rectangular coordinate system

In [ ]:
plot( Θ, r, proj = :ortho, m = 2 )
Out[0]:

Let's try to build a graph in polar coordinate system using only canvas and graph output tool for dynamic models ().

Polar plot for the dynamic model

To build a polar plot for a dynamic model without resorting to interactive scripting tools, we will need to convert vectors from a rectangular coordinate system to a polar system.

Consider the following model (draw_polar_engee_logo.engee):

image.png

If you run it using the , it will plot the following graph:

engee_logo_plot.png

Let's analyse this model using the software simulation management tools.

In [ ]:
modelName = "draw_polar_engee_logo";
model = modelName in [m.name for m in engee.get_all_models()] ? engee.open( modelName ) : engee.load( "$(@__DIR__)/$(modelName).engee");

We can examine what piecewise linear dependencies are defined in each block LUT, without running a simulation, but simply by referring to the properties of each block.

In [ ]:
# Анализируем первую таблицу подстановок
x1 = engee.get_param( modelName*"/LUT1", "BreakpointsForDimension1" );
y1 = engee.get_param( modelName*"/LUT1", "Table" );

# Анализируем вторую таблицу подстановок
x2 = engee.get_param( modelName*"/LUT2", "BreakpointsForDimension1" );
y2 = engee.get_param( modelName*"/LUT2", "Table" );

# Построим график
plot(
    plot( x1, y1, legend=false ),
    plot( x2, y2, legend=false )
)
Out[0]:

As a result, the model plots in a rectangular coordinate system, but outputs them after a transformation that interprets the input signals as data in a polar coordinate system.

The output graph is the sum of two graphs in the polar coordinate system. The first one sets the position of the centre line of each of the two curves that make up the logo (curve LUT2, its radius 1.0). The second component (curve LUT1, displayed with radius 0.25) models the deviation from the centre line.

The coordinate transformation is done in two different ways. Both are interchangeable. In the first case we transform coordinates using simple blocks from the base palette:

image.png

In the second case, we use the Engee Function block with the following code performing the same operations:

struct Block <: AbstractCausalComponent
    # No parameters
end

function (c::Block)(t::Real, α, r)
    x = r * sin( α )
    y = r * cos( α )
    return (x,y)
end

Let's display the graph that our model builds:

In [ ]:
gr()
s = engee.run( modelName, verbose=false );
plot( s["y"].value, s["x"].value, aspect_ratio=:equal )
Out[0]:

Conclusion

In Engee there are gradually more and more sophisticated plotting tools that you can work with without programming.

In this demonstration we have shown how to plot in polar coordinates without programming (or, alternatively, how to do it using the Engee Function block).

Unlike graphs in an interactive script, dynamic model graphs can be updated right as the simulation progresses, which creates interesting possibilities for interactive model simulation.

Blocks used in example