Pages

Mar 29, 2016

Calculate the counter-clock-wise angle degree between two vectors

from __future__ import division
from math import atan2
# reference: http://stackoverflow.com/questions/23408572/angle-between-two-points-0-360-cw
def calcVectAngle(vec1, vec2):
""" calculate the counter-clock-wise angle between two vectors """
angle = atan2(vec1[1], vec1[0]) - atan2(vec2[1], vec2[0])
angle = angle * 360 / (2 * pi)
if angle < 0:
angle += 360
print angle
view raw VectorAngle.py hosted with ❤ by GitHub

Feb 6, 2016

Execute python code using ./

Step1: add #!/usr/local/bin/python in the first line of the code
Step2: in the bash, type chmod +x myscript.py
Step3: type ./myscript.py to execute the python code

Dec 19, 2015

"[[0] * n] * m" is not equal to "[[0 for i in range(n)] for j in range(m)]"

# When generate list of list, be careful of following methods, they produce different results
>>> x = [[0] * 2] * 3
>>> x
[[0, 0], [0, 0], [0, 0]]
>>> y = [[0 for i in range(2)] for j in range(3)]
>>> y
[[0, 0], [0, 0], [0, 0]]
# although they look the same and are equal to each other
>>> x == y
True
# but... the operation can generate different results
>>> x[0][0] = 1
>>> x
[[1, 0], [1, 0], [1, 0]] # Surprise!! every list is changed
>>> y[0][0] = 1
>>> y
[[1, 0], [0, 0], [0, 0]] # this is what we expected
view raw List.py hosted with ❤ by GitHub

Oct 26, 2015

Use Jazzy to generate Swift documentation.

Format:
  • /// description
  • - parameter param: description
  • - returns: xxxxxxx

run Jazzy
$ jazzy --min-acl internal --swift-version 2.1

Oct 20, 2015

Embed images to latex

\graphicspath{ {pic/} } % The folder containing images.
\includegraphics[scale=0.5]{imageName} % Embed a image.