Updated Binary STL File Reader

bent_plate

A recent comment on the post titled binary stl file reader in numpy prompted me to revisit the code and while I was looking at it , I updated the same for code to view the loaded stl file.

The above picture shows the result.

The code as usual available on github from here

from binarySTLreader import BinarySTL,ShowSTLFile
h,p,n,v1,v2,v3=BinarySTL('bent_plate.stl')
ShowSTLFile(v1,v2,v3)
Advertisements

OD Command in Windows with Python

I have seen OD command for last two years but had never bothered to look it up. It always remained under the surface.

Life went on well without it, until now.

During a recent debugging crisis, had to resort to this command for an efficient way to check binary results. All the while had to go to Linux and copy the files. This is when I knew I have to see what this OD is?

OD is octal dump. Simple functionality, don’t know if there is a windows equivalent. So before searching for a windows equivalent, I knew I can replicate this in python and here’s my first attempt.

Works for me and suits my requirement. Not an entire mimic of actual OD command but if you are looking for long and double precision values, this does the job.

I have kept the command line arguments similar to the actual OD command. Here’s a simple demo.

As always, the code is available from my github repo here. Hope to add more functionality as and when I get more time. Please free to fork and play around.

Special thanks to Andy for introducing the command and helping me make sense of the important arguments.

Quick Gantt Chart with Matplotlib

ProjectPlan_GANTT_CHart_MatplotlibThe problem: You need a quick Gantt chart for a quick proposal report and you dint have any project planner software installed.

Solution:

While there are many different ways, you only have access to python, well Here’s a simple Gantt chart plotter with just matplotlib.

Not for rigorous use but a good substitute to make quick Gantt plot for quick report.

Continue reading

Quick Intro to 2D and 3D Visualization in Python

contour_visualization_with_python
Posted a quick tutorial introducing visualization in python.

This tutorial offers a quick look at some common 2d and 3d Visualization available in python. This tutorial is meant to give anyone a quick start in matplotlib and mayavi.mlab.

The tutorial was written as part of CSRP program of AeSIAA which I am volunteering as a mentor to few aeronautical students.

View the tutorial by clicking this Quick Intro to 2D and 3D Visualization in Python

Analysing Trusses – a python program

truss_in_python

Was digging into my laptop and found this Truss program written in python. Computes, displacement, stresses and reactions.


"""
Created on Thu May 08 07:07:24 2014

@author: Sukhbinder Singh

Truss FEM

"""
from __future__ import division
import numpy as np

modE=30.0e6
Area=2.0


#numElem=3
#numNodes=4

elemNodes=np.array([[0,1],[0,2],[0,3]])
nodeCords=np.array([[0.0,0.0],[0.0,120.0],[120.0,120.0],[120.0,0]])

#'''
elemNodes=np.array([[0,1],[0,2],[1,2],[1,3],
                    [0,3],[2,3],[2,5],[3,4],[3,5],[2,4],[4,5]])

nodeCords=np.array([
[0.0,0.0],[0.0,3000.0],
[3000.0,0.0],[3000.0,3000.0],
[6000.0,0.0],[6000.0,3000.0]
])


modE=70000
Area=300
#'''

numElem=elemNodes.shape[0]
numNodes=nodeCords.shape[0]

xx=nodeCords[:,0]
yy=nodeCords[:,1]

EA=modE*Area
tdof = 2*numNodes #total number of degrees of freedom
disps=np.zeros((tdof,1))
force=np.zeros((tdof,1))
sigma=np.zeros((numElem,1))
stiffness=np.zeros((tdof,tdof))
np.set_printoptions(precision=3)

'''
force[1]=-10000.0
presDof=np.arange(2,9)

'''
force[3]=-50000.0
force[7]=-100000.0
force[11]=-50000.0

presDof=np.array([0,1,9])
#'''

for e in xrange(numElem):
    indice= elemNodes[e,:]
    elemDof=np.array([indice[0]*2, indice[0]*2+1, indice[1]*2, indice[1]*2+1 ])
    xa=xx[indice[1]]-xx[indice[0]]
    ya=yy[indice[1]]-yy[indice[0]]
    len_elem=np.sqrt(xa*xa+ya*ya)
    c=xa/len_elem
    s=ya/len_elem
    k1=(EA/len_elem)* np.array([[c*c,c*s,-c*c, -c*s],
                                [c*s,s*s,-c*s ,-s*s],
                                [-c*c,-c*s,c*c,c*s],
                                [-c*s,-s*s,c*s,s*s]])
    stiffness[np.ix_(elemDof,elemDof)] +=k1


actDof=np.setdiff1d(np.arange(tdof),presDof)

disp1=np.linalg.solve(stiffness[np.ix_(actDof,actDof)],force[np.ix_(actDof)]);
disps[np.ix_(actDof)]=disp1


# stresses at elements

for e in xrange(numElem):
    indice= elemNodes[e,:]
    elemDof=np.array([indice[0]*2, indice[0]*2+1, indice[1]*2, indice[1]*2+1 ])
    xa=xx[indice[1]]-xx[indice[0]]
    ya=yy[indice[1]]-yy[indice[0]]
    len_elem=np.sqrt(xa*xa+ya*ya)
    c=xa/len_elem
    s=ya/len_elem
    sigma[e] = (modE/len_elem) * np.dot(np.array([-c,-s,c,s]),disps[np.ix_(elemDof)])

        
print disps
print sigma

react = np.dot(stiffness,disps)
print react.reshape((numNodes,2))



Map Your Google Location History in 3D

Map Your Google Location History in 3D

Inspired by this post “Map Your Google Location History”, I re-mashed the excellent tutorial and added a new function to view google location history on a 3D globe.

Basemap is cool but VTK visualisation toolkit is cooler. Check the results.

And here’s the python notebook to generate the above result.

Cool isn’t it?