Skip to content

Instantly share code, notes, and snippets.

@wwwins
Created March 13, 2017 07:37
Show Gist options
  • Select an option

  • Save wwwins/5f7d58df3dd5e6f12a6c87c42cdbe8bb to your computer and use it in GitHub Desktop.

Select an option

Save wwwins/5f7d58df3dd5e6f12a6c87c42cdbe8bb to your computer and use it in GitHub Desktop.
Get base station positions and direction matrices.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import argparse
if len(sys.argv) < 3:
print("""
Usage:
python getlightsource.py "b0 origin 2.113770 1.062783 1.846117 matrix 0.738652 -0.146207 0.658040 0.033019 0.982870 0.181316 -0.673277 -0.112202 0.730827" "b1 origin -2.054813 1.115880 -1.950253 matrix -0.653711 0.083806 -0.752089 0.046773 0.996423 0.070377 0.755297 0.010829 -0.655293"
""")
sys.exit(-1)
def myformat(arr):
return ' {{\n\t{{ {0:1.5f}f,{1:1.5f}f,{2:1.5f}f,\n\t {3:1.5f}f,{4:1.5f}f,{5:1.5f}f,\n\t {6:1.5f}f,{7:1.5f}f,{8:1.5f}f }},\n\t{{ {9:1.5f}f,{10:1.5f}f,{11:1.5f}f }}\n }}'.format(float(arr[3]),float(arr[4]),float(arr[5]),float(arr[6]),float(arr[7]),float(arr[8]),float(arr[9]),float(arr[10]),float(arr[11]),float(arr[0]),float(arr[1]),float(arr[2]))
def dump(output):
print "copy and paste to geometry.cpp"
print "=============================="
print "static lightsource lightsources[2] = {"
print output[0]+","
print output[1]
print "};"
print "=============================="
def main():
output = []
for zzz in [sys.argv[1],sys.argv[2]]:
arr = zzz.split(' ')
for z in ['b0','b1','origin','matrix']:
try:
arr.remove(z)
except ValueError:
pass
output.append(myformat(arr))
dump(output)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment