from numpy import sin, pi
width = 20  # nm
epsilon = 0.001  # needed to account for the rounding error
dz = 0.5* width * sin(pi/4) + epsilon
print("Particle is shifted by ", round(dz,3), " nm")
print("New particle position Z = ", round(-50 + dz, 3), " nm")

"""
Explanation: Exercise 1: particle positioning


Click on the particle in the sample design area. Check $Z$ value in the Position Offset field on the right panel. $Z=0$, this is default value.

The 3D Viewer shows, that the particles are on top of the substrate.



Set $Z=10$. Check with the 3D Viewer: the particles are now flying above the substrate.

Switch to Simulation view and click Run simulation button. You should be able to see the clear difference.

Left: $Z=0$, right: $Z=10$


Switch back to the Sample view. Drag and drop a new layer to the multilayer, place it in the middle, between air and substrate layers. Click on the new layer. Go to the properties on the right pannel and set Thickness to be 50 nm. Click on the Material to start the Material editor widget. Create a new material with $\delta = 2\times 10^{-6}$, $\beta = 1.3\times 10^{-8}$ and assign it to this layer. 


Disconnect Particle layout from the air layer and connect it to the intermediate layer.

Click on the particle and check $Z$ value in the Position Offset field on the right panel. $Z=10$ and this value is incorrect. For the particles in the intermediate layer, $Z$ must be $\leq 0$. 3D Viewer shows, that particles are not in the intermediate layer, but flying above it.



Vary $Z$ value in the Position Offset field on the right panel:


if particles are on the bottom of the intermediate layer, $Z=-50$ nm



if particles are in the middle of the intermediate layer, $Z=-\frac{50}{2}-\frac{10}{2}=-30$ nm
 


if particles are touching the bottom of the intermediate layer, $Z=-10$ nm.





Exercise 2: particle rotation
Rotate particles around X axis by 45 degree.

As you can see from the 3D view, particles are got shifted along $Z$ axis. 

Since this is not an intend of this exercise, we need to adjust their vertical position.

Initial particle position was on the bottom of the polymer layer, e. g. $Z=-50$ nm. Rotation around the X axis has shifted the particle bottom by $\Delta z = 0.5\cdot w\cdot \sin(\pi/4)$ nm down, where $w=20$ nm is the particle width. The position need to be adjusted to $Z=-50 + \Delta z$ nm to keep particles on the bottom of the layer.
End of explanation
"""


length = 30  # nm
epsilon = 0.001  # needed to account for the rounding error
dz = 0.5* length * sin(pi/4) + epsilon
print("Particle is shifted by ", round(dz,3), " nm")
print("New particle position Z = ", round(-50 + dz, 3), " nm")

"""
Explanation: After adjustment of the particle vertical position, all boxes are at the bottom of the polymer layer, but don't cross it.

Rotate particles around Y axis by 45 degree.
This case is similar to rotation aroung the X axis. The vertical position of the particles is also should be adjusted. The only difference is that the length of the particle should be used instead of width to calculate the adjustment.
End of explanation
"""


