# Polar Image

The DisplayPolarImage macro accepts a 2-D matrix of radius and angle and creates an image plot from the data.

The method involves interpolating to a grid, using NaN to render the portion outside of the polar circle transparent.

This version adds two parameters to set the angle=0 location and whether angles increase clockwise or counter-clockwise.

#pragma rtGlobals=1     // Use modern global access method.

String mat
Variable xIsAngle=1 // X Scaling
Prompt xIsAngle,"Angle from",popup,"X scaling;Y scaling;"   // 1,2
String angle0WhereStr= "right"  // 0 degrees
Prompt angle0WhereStr, "Angle 0 at:", popup, "top;left;right;bottom;"
String angleDirectionStr="counter-clockwise"
Prompt angleDirectionStr, "Angles Increase:", popup, "clockwise;counter-clockwise;"

Silent 1; PauseUpdate
MatrixToXYZ(mat,mat,2,2)    // creates mat+"X", mat+"Y", mat+"Z" waves

String zWave= mat+"Z"

if( xIsAngle == 1 ) // X dimension is angle
angleWave= mat+"X"
else    // Y dimension is angle
angleWave= mat+"Y"
endif

if( degreesOrRadians == 1 ) // degrees
\$angleWave *= pi/180    // convert to radians
endif

// Apply polar to rectangular conversion into an XYZ matrix
Variable zeroAngleWhere=0
if( CmpStr(angle0WhereStr,"top") == 0 )
zeroAngleWhere= 90
endif
if ( CmpStr(angle0WhereStr,"left") == 0 )
zeroAngleWhere= 180
endif
if ( CmpStr(angle0WhereStr,"bottom") == 0 )
zeroAngleWhere= -90
endif
Variable angleDirection = 1 // clockwise
if( CmpStr(angleDirectionStr, "counter-clockwise") == 0 )
angleDirection= -1
endif

// Change of Variables
String yWave= angleWave

// Create and display a (rectangular) image from the resulting XY (circular) domain
String matName= UniqueName(mat+"Image",1,0)
XYZtoMatrix(xWave,matName,yWave,,zWave,,2,) // specify your own density and whether to display
End

// convert two waves in-place from radius, angle (in radians!) to x,y
Variable zeroAngleWhereDegrees  // 0 is right, -90 is bottom, 90 is top, +/180 is left
Variable positiveForClockwise

Variable isClockwise= positiveForClockwise > 0

Variable i, n= numpnts(rw)
Variable xx, yy
for(i=0; i<n; i+=1 )
Variable angle= aw[i]
if( isClockwise )
else
endif
xx= rw[i] * cos(angle)
yy= rw[i] * sin(angle)
rw[i]= xx
aw[i]= yy
endfor
end

Variable nx=25
Variable ny=50
Make/O/N=(nx,ny) matrix
SetScale x -180, 180, "deg", matrix     // x dimension is angle, +/- pi
SetScale y 3,50,"m", matrix         // y dimension is radius, 3 to 50
matrix=  y * sin(x/180*pi) * sin(x/180*pi)
Newimage matrix
ModifyGraph nticks(top)=5
End

Forum

Support

Gallery