## Archive for the ‘Code’ Category

### Rhino 5 and new IronPython installations

Rhino 5 ships with a version of IronPython (2.7.0), but we recommend updating your IronPython version to one of the newer releases, with a few caveats.

### Creating functions dynamically

Sometimes you want to create functions on the fly, at runtime. This came up when using some of the SciPy optimisation functions that require constraints on the variables to be defined as functions.

### Bitwise operators in Python

Python has logical operators (like ‘and’) and bitwise operators (like ‘&’). Bitwise operators are not that common in Python code, but they can be extremely useful in some cases. For example, in RhinoPython they are used to work with geometry type filters.

### Computational Geometry in Python

This post provides a list of Python functions that are very common in structural design calculations. They are not specifically optimised in any way. Therefore, you may end up using entirely different implementations in a real project. The list is a work in progress. I will try to add more examples soon…

### Dynamic plotting with matplotlib

Matplotlib is a great tool to visualise two-dimensional geometric data (and 3D data to some extent). You can also use it to dynamically visualise the convergence of an iterative solver.

### Running Matlab as a Python subprocess

Although NumPy and Scipy usually provide all the tools you need (and more) for scientific computing, sometimes you may want to use a bit of Matlab in the background. In my case, for example, to use rref. Conveniently, Matlab can be run as a Python subprocess, provided of course that Matlab is installed on your system.

### Adding methods to Python classes

The normal way to add functionality (methods) to a class in Python is to define functions in the class body. There are many other ways to accomplish this that can be useful in different situations.

### Working with Sublime

Sublime Text is great, but using it properly is not as transparent as what most of us are used to. I will try to list here some of the things i had to figure out to start working efficiently.

### Using Jonathan Shewchuk’s Triangle library with Python

Python Triangle is a python wrapper around Jonathan Richard Shewchuk’s two-dimensional quality mesh generator and delaunay triangulator library. According to the Python Triangle docs, installation is straightforward. However, at least on my system, it didn’t work right out of the box. Luckily, the fix is quite simple.

### TeXlipse and Biblatex

Biblatex is a package for LateX that provides more control over the way references are managed. A quick introduction can be found here, and more detailed information here. Using the package with all the default values works great, but then you are not really making the most of it. Once you start changing options, there is one important thing you should know…