Commit 60cb967b by Benjamin Michelland

### Script: Script that draws a polar plot from a BRDF and a data file.

parent 7208fee8
 import alta import os import numpy as np from sys import argv import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button, RadioButtons def rotate_normal(vec, theta): cost = np.cos(theta) sint = np.sin(theta) temp = cost * vec[0] - sint * vec[1] vecout = [0,0,0] vecout[2] = vec[2] vecout[1] = cost * vec[1] + sint * vec[0] vecout[0] = temp return vecout #end def rotate_binormal(vec, theta): cost = np.cos(theta) sint = np.sin(theta) temp = cost * vec[0] + sint * vec[2] vecout = [0,0,0] vecout[1] = vec[1] vecout[2] = cost * vec[2] - sint * vec[0] vecout[0] = temp return vecout #end def cart2Rusin(x): half = [x[0]+x[3],x[1]+x[4],x[2]+x[5]] norm = half[0]*half[0]+half[1]*half[1]+half[2]*half[2] half = half/np.sqrt(norm) diff = rotate_normal(x,-np.arctan2(half[1],half[0])) diff = rotate_binormal(diff,np.arccos(half[2])) d_x = [np.arccos(half[2]),np.arccos(diff[2]),np.arctan2(diff[1],diff[0])] return d_x #end if len(argv) < 3: print '<> you did not specify the input argument correctly:' print ' polar_plot.py inputBrdf inputData (thetaIncident)' exit() #end theta = np.arange(0, np.pi, 0.001) r = np.zeros(theta.size) g = np.zeros(theta.size) b = np.zeros(theta.size) d_r = np.zeros(theta.size) d_g = np.zeros(theta.size) d_b = np.zeros(theta.size) rmax = 0.0 d = alta.load_data('vertical_segment',argv[2]) filename = argv[1] f = alta.load_function(filename) for i in range(0, r.size): thetai = theta[i]-0.5*np.pi if len(argv) < 4 : x = [0.0, 0.0, 1.0, np.sin(thetai), 0.0, np.cos(thetai)] else : x = [np.sin(float(argv[3])), 0.0, np.cos(float(argv[3])), np.sin(thetai), 0.0, np.cos(thetai)] d_x = cart2Rusin(x) y = f.value(x) d_y = d.value(d_x) r[i] = y[0] g[i] = y[1] b[i] = y[2] d_r[i] = d_y[0] d_g[i] = d_y[1] d_b[i] = d_y[2] rmax = max(r[i], rmax); rmax = max(g[i], rmax); rmax = max(b[i], rmax); rmax = max(d_r[i], rmax); rmax = max(d_g[i], rmax); rmax = max(d_b[i], rmax); ax = plt.subplot(111, polar=True) ax.plot(theta, r, color='r', linewidth=3) ax.plot(theta, g, color='g', linewidth=3) ax.plot(theta, b, color='b', linewidth=3) ax.plot(theta, d_r, color='r', linewidth=2,linestyle='--') ax.plot(theta, d_g, color='g', linewidth=2,linestyle='--') ax.plot(theta, d_b, color='b', linewidth=2,linestyle='--') ax.set_rmax(1.1*rmax) ax.grid(True) (filename,ext) = os.path.splitext(os.path.basename(argv[1])) ax.set_title("Plotting " + filename + " at normal incidence" , va='bottom') plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!