/*-------------------------------------------------------------------------

Hit ctrl-enter to execute.

Description:

	This script generates a two dimensional plane wave at an specified
	angle to the x-axis and period in pixels.

	Copyright 2001 Gatan inc. 

--------------------------------------------------------------------------*/

// Define required parameters
// PeriodPix is the period in pixels
// thetaDeg is the plane wave angle wrt the x-axis
// deltadeg is the wave phase offset
number imgSize = 256
number periodPix = 8
number thetaDeg = 60
number deltaDeg = 0
number Ax, Ay, deltaRad, originPix

// Create output image with appropriate title
string imgName = "2D plane wave"
imgName = imgName + "." + periodPix + "." + thetaDeg + "." + deltaDeg
image img := RealImage(imgName, 4, imgSize, imgSize)

// Define the x and y plane wave amplitudes
Ax = 2 * pi() * cos(thetaDeg * pi() / 180) / periodPix
Ay = -2 * pi() * sin(thetaDeg * pi() / 180) / periodPix

// Convert the phase phase shift into radians, 
// and define the origin of the image as its centre
deltaRad = deltaDeg * pi() / 180
originPix = imgSize / 2

// Apply the equation for a 2D plane wave at angle theta to X axis 
// using icol and irow
img = sin(Ax * (icol - originPix) + Ay * (irow - originPix) - deltaRad)

// Show the 2d phase image 
ShowImage(img)