Difference between revisions of "Talk:Geometry:WAXS 3D"

From GISAXS
Jump to: navigation, search
(Created page with "====Check==== :<math> \begin{alignat}{2} \left ( \frac{q}{k} \right )^2 d^{\prime 2} & = \begin{alignat}{2} [ & \left( x \cos \phi_g -\sin \phi_g ( d \cos \theta_g - z \si...")
 
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
====Check====
+
<source lang="python" line>
:<math>
+
#!/usr/bin/python
\begin{alignat}{2}
+
# Quick/rough Python code to check (numerically) the derivations...
\left ( \frac{q}{k} \right )^2 d^{\prime 2}
+
import numpy as np
    & = \begin{alignat}{2} [ & \left( x \cos \phi_g -\sin \phi_g ( d \cos \theta_g - z \sin \theta_g ) \right)^2 \\ & + \left( x \sin \phi_g + \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) - d^{\prime} \right)^2 \\ & + \left( d \sin \theta_g + z \cos \theta_g \right)^2  ] \end{alignat}  \\
 
  
     & = \begin{alignat}{2} [
+
for i in range(10):
      & x^2 \cos^2 \phi_g - x \cos \phi_g \sin \phi_g ( d \cos \theta_g - z \sin \theta_g ) + \sin^2 \phi_g ( d \cos \theta_g - z \sin \theta_g )^2  \\
+
      
      & + x^2 \sin^2 \phi_g + x \sin \phi_g \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) - d^{\prime} x \sin \phi_g \\
+
    x = np.random.uniform(-10,10)
      & + \cos \phi_g ( d \cos \theta_g - z \sin \theta_g )x \sin \phi_g + \cos^2 \phi_g ( d \cos \theta_g - z \sin \theta_g )^2 - d^{\prime} \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) \\
+
    z = np.random.uniform(-10,10)
      & - d^{\prime} x \sin \phi_g - d^{\prime} \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) + d^{\prime 2} \\
+
    d = np.random.uniform(10,1000)
      & + d^2 \sin^2 \theta_g + 2 d \sin \theta_g z \cos \theta_g + z^2 \cos^2 \theta_g ] \end{alignat} \\
+
   
 +
   
 +
    phi = np.random.uniform(-np.pi, +np.pi)
 +
    theta = np.random.uniform(0, +np.pi)
 +
   
 +
    print( 'x{:+05.1f} d{:+06.1f} z{:+05.1f} phi{:+06.1f} theta{:+06.1f}'.format(x, d, z, np.degrees(theta), np.degrees(phi)) )
  
     & = \begin{alignat}{2} [
+
     #k = 1.0
      & x^2 \cos^2 \phi_g - x \cos \phi_g \sin \phi_g ( d \cos \theta_g - z \sin \theta_g ) + \sin^2 \phi_g ( d \cos \theta_g - z \sin \theta_g )^2  \\
+
   
      & + x^2 \sin^2 \phi_g + 2 x \sin \phi_g \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) - 2 d^{\prime} x \sin \phi_g \\
+
    v2y = d*np.cos(theta) - z*np.sin(theta)
      & + \cos^2 \phi_g ( d \cos \theta_g - z \sin \theta_g )^2 - 2 d^{\prime} \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) + d^{\prime 2} \\
+
    dprime = np.sqrt( np.square(x) + np.square(d) + np.square(z) )
      & + d^2 \sin^2 \theta_g + 2 d \sin \theta_g z \cos \theta_g + z^2 \cos^2 \theta_g ] \end{alignat} \\
+
   
 +
    qx = x*np.cos(phi) - np.sin(phi)*v2y
 +
    qy = x*np.sin(phi) + np.cos(phi)*v2y - dprime
 +
    qz = d*np.sin(theta) + z*np.cos(theta)
 +
   
 +
    q = np.sqrt( np.square(qx) + np.square(qy) + np.square(qz) )
 +
   
 +
   
 +
   
 +
   
 +
    print( '    pieces qx{:g} qy{:g} qz{:g} q{:g}'.format(qx, qy, qz, q) )
 +
    #print( '{}{:g}'.format( ' '*50, q) )
 +
   
 +
    if False:
 +
        l1 = np.square(qx)
 +
        l2 = np.square(qy)
 +
        l3 = np.square(qz)
 +
        qalt2 = l1 + l2 + l3
  
     & = \begin{alignat}{2} [
+
     if False:
      & x^2  - x \sin \phi_g \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) + ( d \cos \theta_g - z \sin \theta_g )^2  \\
+
        l1 = np.square(x*np.cos(phi) - np.sin(phi)*(d*np.cos(theta) - z*np.sin(theta)))
      & + 2 x \sin \phi_g \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) - 2 d^{\prime} x \sin \phi_g \\
+
        l2 = np.square(x*np.sin(phi) + np.cos(phi)*(d*np.cos(theta) - z*np.sin(theta)) - dprime)
      & - 2 d^{\prime} \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) + d^{\prime 2} \\
+
        l3 = np.square(d*np.sin(theta) + z*np.cos(theta))
      & + d^2 \sin^2 \theta_g + 2 d z \sin \theta_g \cos \theta_g + z^2 \cos^2 \theta_g ] \end{alignat} \\
+
        qalt2 = l1 + l2 + l3
 +
       
 +
    if True:
 +
        l1 = np.square(x)*np.square(np.cos(phi)) - 2*x*np.cos(phi)*np.sin(phi)*v2y + np.square(np.sin(phi))*np.square(v2y)
 +
        l2 = np.square(x)*np.square(np.sin(phi)) + x*np.sin(phi)*np.cos(phi)*v2y - dprime*x*np.sin(phi)
 +
        l3 = x*np.sin(phi)*np.cos(phi)*v2y + np.square(np.cos(phi))*np.square(v2y) - dprime*np.cos(phi)*v2y
 +
        l4 = -1*dprime*x*np.sin(phi) - dprime*np.cos(phi)*v2y + np.square(dprime)
 +
        l5 = np.square(d)*np.square(np.sin(theta)) + 2*d*z*np.sin(theta)*np.cos(theta) + np.square(z)*np.square(np.cos(theta))
 +
       
 +
        qalt2 = l1 + l2 + l3 + l4 + l5
 +
       
 +
    if True:
 +
       
 +
        qalt2 = 2*dprime*( dprime - x*np.sin(phi) - np.cos(phi)*v2y )
  
    & = \begin{alignat}{2} [
 
      & x^2  + d^2 \cos^2 \theta_g - 2 dz \cos \theta_g \sin \theta_g + z^2 \sin^2 \theta_g  \\
 
      & + ( - x \sin \phi_g \cos \phi_g + 2 x \sin \phi_g \cos \phi_g - 2 d^{\prime} \cos \phi_g )( d \cos \theta_g - z \sin \theta_g ) \\
 
      & - 2 d^{\prime} x \sin \phi_g \\
 
      & + d^{\prime 2} \\
 
      & + d^2 \sin^2 \theta_g + 2 d z \sin \theta_g \cos \theta_g + z^2 \cos^2 \theta_g ] \end{alignat} \\
 
  
     & = \begin{alignat}{2} [
+
     qalt = np.sqrt(qalt2)
      & d^{\prime 2} + x^2  + d^2 + z^2 - 2 dz \cos \theta_g \sin \theta_g  \\
+
   
      & + ( x \sin \phi_g \cos \phi_g - 2 d^{\prime} \cos \phi_g )( d \cos \theta_g - z \sin \theta_g ) \\
+
    print( '    qalt {:g}'.format(qalt) )
      & + 2 d z \sin \theta_g \cos \theta_g - 2 d^{\prime} x \sin \phi_g  ] \end{alignat} \\
+
    print( '{}{:g}'.format( ' '*50, q-qalt) )
  
    & = 2 d^{\prime 2} - 2 d^{\prime} x \sin \phi_g + ( x \sin \phi_g \cos \phi_g - 2 d^{\prime} \cos \phi_g )( d \cos \theta_g - z \sin \theta_g ) \\
+
</source>
 
 
    & = 2 d^{\prime 2} - 2 d^{\prime} x \sin \phi_g + ( x \sin \phi_g - 2 d^{\prime} )\cos \phi_g( d \cos \theta_g - z \sin \theta_g ) \\
 
 
 
 
 
    & = ? \\
 
    & = ? \\
 
    & = 2 d^{\prime 2} - 2 d^{\prime} x \sin \phi_g + 2 d^{\prime} \cos \phi_g ( d \cos \theta_g - z \sin \theta_g )  \\
 
    & = 2 d^{\prime} \left( d^{\prime} - x \sin \phi_g + \cos \phi_g ( d \cos \theta_g - z \sin \theta_g ) \right) \\
 
\left( \frac{q}{k} \right)^2
 
    & = 2 \left( 1 - \frac{x \sin \phi_g + \cos \phi_g ( d \cos \theta_g - z \sin \theta_g )}{d^{\prime} } \right)
 
\end{alignat}
 
</math>
 

Latest revision as of 17:22, 13 January 2016

#!/usr/bin/python 
# Quick/rough Python code to check (numerically) the derivations...
import numpy as np

for i in range(10):
    
    x = np.random.uniform(-10,10)
    z = np.random.uniform(-10,10)
    d = np.random.uniform(10,1000)
    
    
    phi = np.random.uniform(-np.pi, +np.pi)
    theta = np.random.uniform(0, +np.pi)
    
    print( 'x{:+05.1f} d{:+06.1f} z{:+05.1f} phi{:+06.1f} theta{:+06.1f}'.format(x, d, z, np.degrees(theta), np.degrees(phi)) )

    #k = 1.0
    
    v2y = d*np.cos(theta) - z*np.sin(theta)
    dprime = np.sqrt( np.square(x) + np.square(d) + np.square(z) )
    
    qx = x*np.cos(phi) - np.sin(phi)*v2y
    qy = x*np.sin(phi) + np.cos(phi)*v2y - dprime
    qz = d*np.sin(theta) + z*np.cos(theta)
    
    q = np.sqrt( np.square(qx) + np.square(qy) + np.square(qz) )
    
    
    
    
    print( '    pieces qx{:g} qy{:g} qz{:g} q{:g}'.format(qx, qy, qz, q) )
    #print( '{}{:g}'.format( ' '*50, q) )
    
    if False:
        l1 = np.square(qx)
        l2 = np.square(qy)
        l3 = np.square(qz)
        qalt2 = l1 + l2 + l3

    if False:
        l1 = np.square(x*np.cos(phi) - np.sin(phi)*(d*np.cos(theta) - z*np.sin(theta)))
        l2 = np.square(x*np.sin(phi) + np.cos(phi)*(d*np.cos(theta) - z*np.sin(theta)) - dprime)
        l3 = np.square(d*np.sin(theta) + z*np.cos(theta))
        qalt2 = l1 + l2 + l3
        
    if True:
        l1 = np.square(x)*np.square(np.cos(phi)) - 2*x*np.cos(phi)*np.sin(phi)*v2y + np.square(np.sin(phi))*np.square(v2y)
        l2 = np.square(x)*np.square(np.sin(phi)) + x*np.sin(phi)*np.cos(phi)*v2y - dprime*x*np.sin(phi)
        l3 = x*np.sin(phi)*np.cos(phi)*v2y + np.square(np.cos(phi))*np.square(v2y) - dprime*np.cos(phi)*v2y
        l4 = -1*dprime*x*np.sin(phi) - dprime*np.cos(phi)*v2y + np.square(dprime)
        l5 = np.square(d)*np.square(np.sin(theta)) + 2*d*z*np.sin(theta)*np.cos(theta) + np.square(z)*np.square(np.cos(theta))
        
        qalt2 = l1 + l2 + l3 + l4 + l5
        
    if True:
        
        qalt2 = 2*dprime*( dprime - x*np.sin(phi) - np.cos(phi)*v2y )


    qalt = np.sqrt(qalt2)
    
    print( '    qalt {:g}'.format(qalt) )
    print( '{}{:g}'.format( ' '*50, q-qalt) )