vector.py

Created by asness

Created on February 26, 2019

1.61 KB

Minified with pyminify: pyminify –remove-literal-statements vector.py » vectormini.py


from math import acos,atan2,cos,degrees,radians,sin,sqrt,tan
def reduce(func,aList):
  A=aList
  if A:
    B=A[0]
    for C in A[1:]:B=func(B,C)
    return B
  return None
def rad(degAngle):return radians(degAngle)
def deg(radAngle):return degrees(radAngle)
def rads(degAngles):return[rad(A)for A in degAngles]
def degs(radAngles):return[deg(A)for A in radAngles]
def C(degAngle):return cos(rad(degAngle))
def S(degAngle):return sin(rad(degAngle))
def T(degAngle):return tan(rad(degAngle))
def AC(x):return deg(acos(x))
def c2p(x,y):return[r([x,y]),deg(atan2(y,x))]
def c2ps(xs,ys):return[c2p(A,B)for(A,B)in(zip(xs,ys))]
def p2c(r,th):return[r*C(th),r*S(th)]
def p2cs(rs,ths):return[p2c(A,B)for(A,B)in(zip(rs,ths))]
I=[1,0,0]
J=[0,1,0]
K=[0,0,1]
def va(a,b):return[A+B for(A,B)in(zip(a,b))]
def vs(aList):return reduce(va,aList)
def vm(a,n):return[n*A for A in a]
def vdist(a,b):return va(b,vm(a,-1))
def r(a):return sqrt(sum([A**2 for A in a]))
def u(a):return vm(a,1.0/r(a))
def md2v(m,d):return vm(u(d),m)
def cp(a,b):
  if len(a)==2:return a[0]*b[1]-a[1]*b[0]
  if len(a)==3:return[a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1]-a[1]*b[0]]
def dp(a,b):return sum([A*B for(A,B)in(zip(a,b))])
def stp(a,b,c):return dp(a,cp(b,c))
def ang(a,b):return AC(dp(a,b)/(r(a)*r(b)))
def axangs(a):return[ang(a,A)for A in((I,J,K))]
def comp(a,b):return dp(a,u(b))
def proj(a,b):return vm(u(b),comp(a,b))
def pldist(a,b,c):B=vdist(a,b);A=vdist(b,c);return r(cp(B,A))/r(A)
def lldist(p1,d1,p2,d2):return stp(vdist(p1,p2),d1,d2)/r(cp(d1,d2))
def fcsys(rs,Fs,PMs=[[0,0,0]]):A=vs(Fs);B=[cp(C,D)for(C,D)in(zip(rs,Fs))];E=va(vs(B),vs(PMs));return A,E

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.