e3_render.py – Classes for rendering 2D and 3D blocks.

It is expected that this module be imported by the application program e3prep.py.

Rendering in 2D Scalable Vector graphics (SVG)

To get an SVG rendering set up, it is usually convenient to set all of the length scales with a call to the window method and then set the parameters for the x and y axes so that they have suitable ranges, tick marks and positions.

class e3_render.SketchEnvironment

A place to put the sketch settings for both Metapost rendering and SVG rendering.

A sketch file will contain a rendering of the geometry objects defining the simulation domain. Since the coordinates for mb_cns are in metres, you will probably have to apply suitable scale factors to get a drawing that can be printed to an A4 page conveniently. Also, because the origin of a postsript figure is in the bottom-left corner of the page, you may have to reset the origin to see all of the geometry elements if some of them have negative coordinates.


Set the state of label printing: True or False

Parameters:label_state – State of label printing: True or False
SketchEnvironment.xaxis(xmin=None, xmax=None, xtic=None, xaxis_offset=None)

Set the x-axis scale parameters.

  • xmin – Minimum value for x-axis scale. (float)
  • xmax – Maximum value for x-axis scale. (float)
  • xtic – Interval between tic marks and labels. (float)
  • xaxis_offset – The vertical offset (from ymin) for drawing the length of the scale. (float) Negative values will lower the x-axis scale.
SketchEnvironment.yaxis(ymin=None, ymax=None, ytic=None, yaxis_offset=None)

Set the y-axis scale parameters.

  • ymin – Minimum value for y-axis scale.
  • ymax – Maximum value for y-axis scale.
  • ytic – Interval between tic marks and labels.
  • yaxis_offset – The horizontal offset (from xmin) for drawing the length of the scale. Negative values will move the y-axis scale to the left.
SketchEnvironment.scales(xscale=None, yscale=None)

Set the scale factors for the drawing.

Model coordinates are multiplied by these scales to get page coordinates.

SketchEnvironment.set_drawing_size(width=None, height=None)

Set the scale factors for the drawing based on a length specified by the user.

Depending on which scale is specified, the function searches the list of defined nodes and finds the max distance from the origin and scales the drawing by setting that distance as that specified in this function by the user.

  • width – The size of the drawing in the x-direction. (Units = metres)
  • height – The size of the drawing in the y-direction. (Units = metres)

Note that only one scale needs to be specified. In the case that one scale is specifed, the drawing will hold true shape and scale in both directions by the same factor (as computed by the function, not as specified by the user). If both are specified, the drawing will be distorted to meet the users demands.

SketchEnvironment.set_length_scale(length=None, ref_length=0.1)

Sets the scale of the drawing given a user specified length.

Reference length is 10cm on the page by default, but can also be changed by user. If no parameters are specified the function searches for the largest orthogonal distance and scales that to the reference length on the page while maintaining true shape.

  • length – User specified length. (Units = metres)
  • ref_length – Reference length. (Units = metres)
SketchEnvironment.origin(x=0.0, y=0.0)

Set the origin on the page for the rendered picture.

For example, it is sometimes good to select an origin of (0.05, 0.05) to get the origin 5 centimetres up and right from the bottom-left corner of the page.

SketchEnvironment.window(xmin=0.0, ymin=0.0, xmax=1.0, ymax=1.0, page_xmin=0.05, page_ymin=0.05, page_xmax=0.17, page_ymax=0.17)

Define a world-view window and a corresponding window on the rendered page.

These windows are defined by the coordinates of their lower-left and upper-right corners. Distances, in both views, are in metres.



Convert radians to degrees.

This is a convenience function for the writing of the MetaPost file but may also be used in the user script.

Parameters:rad – angle in radians.
Returns:angle in degrees