Visualizing 3d Triangles With Pure Matplotlib Function

The problem: STL file is read, you want to do a quick sanity check if it’s correct and don’t have access to VTK or third party STL viewer.

Solution: Use matplotlib to visualize the STL.

Here’s a simple matplotlib script to visualize the STL triangles.


# coding: utf-8
import mpl_toolkits.mplot3d as a3d
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import numpy as np

fname=r'coordtopo.npy'

coords,topo=np.load(fname)
ax = a3d.Axes3D(plt.figure())

xm,ym,zm=coords.max(axis=0)
xmi,ymi,zmi =coords.min(axis=0)

for nodes in topo:
tri = a3d.art3d.Poly3DCollection([coords[nodes,:3]])
tri.set_color(colors.rgb2hex([0.9,0.6,0.]))
tri.set_edgecolor('k')
ax.add_collection3d(tri)

ax.set_xlim3d([xmi,xm])
ax.set_ylim3d([ymi,ym])
ax.set_zlim3d([zmi,zm])

plt.show()

Four Thoughts For 2016

Four thoughts from the readings (including books) in 2015 for 2016.

  

Sharing it here. 
Think Long Term

If everything you do needs to work on a three-year time horizon, then you’re competing against a lot of people. But if you’re willing to invest on a seven-year time horizon, you’re now competing against a fraction of those people, because very few companies are willing to do that. Just by lengthening the time horizon, you can engage in endeavors that you could never otherwise pursue. 

-Amazon’s Jeff Bezos said this in an interview in 2011


Be a Learning Machine

As far as knowledge is concerned, Charlie Munger says – “The more basic knowledge you have, the less new knowledge you have to get.”

It’s not something you do just to advance in life. As a corollary to that proposition which is very important, it means that you are hooked for lifetime learning. And without lifetime learning, you people are not going to do very well. You are not going to get very far in life based on what you already know. You’re going to advance in life by what you learn after you leave here. [Source: Munger; USC 2007]


Life is long enough

It is not that we have a short time to live, but that we waste a lot of it. Life is long enough, and a sufficiently generous amount has been given to us for the highest achievements if it were all well invested. But when it is wasted in heedless luxury and spent on no good activity, we are forced at last by death’s final constraint to realize that it has passed away before we knew it was passing. So it is: we are not given a short life but we make it short, and we are not ill-supplied but wasteful of it… Life is long if you know how to use it.

-Seneca wrote


Be thankful for what you got

I am sometimes taken aback by how people can have a miserable day or get angry because they feel cheated by a bad meal, cold coffee, a social rebuff or a rude reception. We are quick to forget that just being alive is an extraordinary piece of good luck, a remote event, a chance of occurrence of monstrous proportions. Imagine a speck of dust next to a planet a billion times the size of earth. The speck of dust represents the odds in favor of your being born; the huge planet would be the odds against it. So stop sweating the small stuff. Don’t be like the ingrate who got a castle as a present and worried about the mildew in the bathroom. Stop looking at the gift horse in the mouth – remember you are a Black Swan. 

[Source: Taleb; The Black Swan]

Solving ‘ld: library not found’ issues after upgrading to OS X El Capitain

 

Upgrading to a new OS is always exciting, but if one uses a system for development, then its not always smooth.

Here’s one issue i recently faced after upgrading to OS X El Capitain.

I was recently converting a fortran program to python on macbook using the f2py and got the following error.

ld: library not found for -lbundle1.o

The code complied but the bundle library was missing during linking , this code worked last time I did it, so the suspect was the new OS X El Capitain.

More specifically the suspect was the Xcode library, so I reinstalled the developer tools using the command:

xcode-select –install

Took 15 minutes but after those minutes, faced a new problem, now gcc_s.10.5 library was missing..  

ld: library not found for -lgcc_s.10.5

This was more tricky than the first problem but quickly found this fix from here.

cd /usr/local/lib

sudo ln -s ../../lib/libSystem.B.dylib libgcc_s.10.5.dylib

These two problems solved. Now back to work. 

Reliability 

 reliability  is a great virtue 

Books 2015

 
Almost all the blogs I follow had a book post this week, that reminded me to look at my reading list for this year. 

So here is it from top to bottom. 

This year was an interesting mix of books and I see an increased focus on investing.

  • The Art of Choosing by Sheena Iyengar
  • Charlie Chaplin by Peter Ackroyd
  • Ebola: The Natural and Human History of a Deadly Virus by David Quammen
  • The Power of Less by Leo Babauta
  • The Little Book of Economics by Ip, G.
  • Hooked by Nir Eyal
  • The Little Book of Big Profits from Small Stocks by Hilary Kramer
  • The Little Book of Valuation: How to Value a Company, Pick a Stock and Profit (Little Books. Big Profits) by Damodaran, Aswath
  • In Defense of Food by Pollan, Michael
  • Thinking, Fast and Slow by Kahneman, Daniel
  • The Element by Ken Robinson
  • The Armchair Economist -Economics & Everyday Life by Landsburg, Steven El
  • So Good They Can’t Ignore You By Newport, Cal
  • Purple cow by Seth Godin
  • Being Mortal Atul Gwande
  • Seeking wisdom from Darwin to Charlie Munger by Peter
  • The Warren Buffet Portfolio by Robert G
  • The Myth of innovation by Scott Berken
  • Permission marketing by Seth Godin
  • The little book of big dividend investing by Charles B. Carlson and Terry Savage
  • The road less travel by M. Scott Peck
  • The Wright Brothers By David McCullough
  • How to drive a tank and other everyday tips for the modern gentleman – Frank Coles
  • The Wandering Mind by Michael C Cornallis
  • Rise of robots: technology and the threat of a jobless future by Martin Ford
  • All marketers are liars by Seth Godin
  • Irrationally yours: on missing stocks, pickup lines and other existential puzzles by Dan Ariely
  • The road to character by David Brooks
  • Surely you are joking Mr. Feynman by Ralph Leighton
  • The selfish gene by Richard Dawkins
  • Misbehaving: the making of behavioral economics by Richard H Thaler
  • Carrots and Sticks by Ian Ayres
  • The invisible gorilla by Chistopher Chabris
  • Standard Deviations by Gary Smith
  • Think twice by Michael J. Mauboussin
  • Stumbling on happiness Daniel Gilbert
  • The rational optimist by Mat Ridley

If I have to choose choose top 5 among the lot then this is the list in no particular order.

  1. Charlie Chaplin
  2. Surely you are joking Mr Feynman
  3. Rational Optimist
  4. Think Twice
  5. Stumbling upon happiness. 

What are your fav reads for 2015?


Year In Search

Here’s an excellent video by Google on the search in 2015. Beautifully crafted!!

Matlab to Python – some code examples

Two years back, I was converting a matlab script to python, here are some of the errors that I encountered during the conversion. Found them documented in that converted script, posting them here for wider audience.

1

Matlab to Python

1. () to []

nd=topo(j,i)
X(j,i)=coords(nd,1)
Y(j,i)=coords(nd,2)

SyntaxError: can't assign to function call

nd=topo[j,i]
X[j,i]=coords[nd,1]
Y[j,i]=coords[nd,2]

2. 1 to 0

X(j,i)=coords(nd,1)
Y(j,i)=coords(nd,2)

IndexError: index (2) out of range (0<=index<2) in dimension 1

X[j,i]=coords[nd,0]
Y[j,i]=coords[nd,1]

3. zeros to zeros

B=zeros(2,edof)

In Python

B=np.zeros((2,edof))

4. array to array

D=G*[1 0; 0 1];

in python

D_ps=G* np.array([[1.0,0.0],[0.0,1.0]])

5. % to #

% is comments in matlab

Python

# is comments in python

6. For to for

for i=1:nnel
node(i)=nodes(iel,i);
end

python

for i in range(nnel):
node[i]=nodes[iel,i]

7. Matlab find to python find

L1 = find(coordinates(:,2)==min(coordinates(:,2)))

in python

l1 = np.where(coords[:,1]==np.min(coords[:,1])
Follow

Get every new post delivered to your Inbox.

Join 1,153 other followers

%d bloggers like this: