Scripting Resources for DigitalMicrograph™ |
Tilt Angle Calculator |
|
Function |
Computes the net tilt between two sets of X and Y goniometer tilts. |
Version |
version:20070907, v2.0 |
Author |
D. R. G. Mitchell |
Acknowledgements |
|
Comments |
This functionality is built into the DiffTools suite of scripts. |
System Requirements |
Should be compatible with all recent versions of DigitalMicrograph. |
Known Issues |
|
Supported |
Yes |
Included Files |
Main script file. |
Source Code |
// Script to calculate the net angle resulting from an initial and final set of goniometer // tilt values. Use this script to calculate the net angle resulting from the two sets of tilts // This may be of use when tilting between zone axes and you wish to confirm that the zone axes // you are working with are consistent with the tilts used.
// D. R. G. Mitchell, September 2007, adminnospam@dmscripting.com (remove the nospam to make this email address work) // v2.0
// version:20070907
class TiltAngleCalculatorClass : uiframe {
void cancelpane( object self) { documentwindow windoc=getdocumentwindow(0) windowclose(windoc,0) }
void calculateangle( object self) { number initialx, finalx, initialy, finaly, nettilt, deltax, deltay, angle
// Get current field values from the dialog
dlggetvalue(self.lookupelement("initxfield"),initialx) dlggetvalue(self.lookupelement("inityfield"),initialy) dlggetvalue(self.lookupelement("finalxfield"),finalx) dlggetvalue(self.lookupelement("finalyfield"),finaly)
// Show the current values in the results window
result("\n********************************\n\nInitial X tilt\t: "+format(initialx,"%5.1f")+" degrees Initial Y tilt\t: "+format(initialy,"%5.1f")+ degrees\n") result("Final X tilt\t: "+format(finalx,"%5.1f")+" degrees Final Y tilt\t\t: "+format(finaly,"%5.1f")+" degrees\n")
// Convert degrees into radians for the trig calculations
initialx=initialx/(180/pi()) initialy=initialy/(180/pi()) finalx=finalx/(180/pi()) finaly=finaly/(180/pi())
deltax=finalx-initialx deltay=finaly-initialy
// Calculate the values of the net tilt using the sine rule
angle=sqrt((((sin(deltax/2)**2)+(sin(deltay/2)**2)))) nettilt=asin(angle)*2*(180/pi())
// Update the dialog field and display the results in window
dlgvalue(self.lookupelement("nettiltfield"), nettilt)
result("Net tilt\t\t: "+format(nettilt,"%5.1f")+" degrees\n\n") }
void AboutToCloseDocument( object self, number test) {
// when the user closes the dialog, the position of the dialog is saved
// this bit gets the position of the dialog and writes it to the persistent notes
number xpos, ypos documentwindow dialogwindow=getframewindow(self) windowgetframeposition(dialogwindow, xpos, ypos)
// Checks to make sure the dialog is not outside the usual viewing area // this can happen if the dialog is accidentally maximised and then closed. // If the position is OK, then it is saved.
if (xpos>=142 && ypos>=24) { setpersistentnumbernote("Diff Tools:Dialog Positions:Tilt Left",xpos) setpersistentnumbernote("Diff Tools:Dialog Positions:Tilt Top",ypos) }
}
}
// make the top box to hold the tilt values
taggroup maketiltboxes() { TagGroup goniometerbox_items TagGroup goniometerbox = DLGCreateBox(" Goniometer Values ", goniometerbox_items).dlginternalpadding(13,8)
// Create the fields for the initial X and X values
taggroup initxlabel=dlgcreatelabel("Initial X") taggroup initxfield = DLGCreateRealField(0, 8, 1).dlgidentifier("initxfield") taggroup initxgroup=dlggroupitems(initxlabel, initxfield).dlgtablelayout(1,2,0).dlgexternalpadding(10,0)
taggroup initylabel=dlgcreatelabel("Initial Y") taggroup inityfield = DLGCreateRealField(0, 8, 1).dlgidentifier("inityfield") taggroup initygroup=dlggroupitems(initylabel, inityfield).dlgtablelayout(1,2,0).dlgexternalpadding(10,0)
taggroup initxandygroup=dlggroupitems(initxgroup, initygroup).dlgtablelayout(2,1,0)
// Create the fields for the final X and X values
taggroup finalxlabel=dlgcreatelabel("Final X") taggroup finalxfield = DLGCreateRealField(0, 8, 1).dlgidentifier("finalxfield") taggroup finalxgroup=dlggroupitems(finalxlabel, finalxfield).dlgtablelayout(1,2,0).dlgexternalpadding(10,0)
taggroup finalylabel=dlgcreatelabel("Final Y") taggroup finalyfield = DLGCreateRealField(0, 8, 1).dlgidentifier("finalyfield") taggroup finalygroup=dlggroupitems(finalylabel, finalyfield).dlgtablelayout(1,2,0).dlgexternalpadding(10,0)
taggroup finalxandygroup=dlggroupitems(finalxgroup, finalygroup).dlgtablelayout(2,1,0) taggroup allgoniometerfieldsgroup=dlggroupitems(initxandygroup, finalxandygroup).dlgtablelayout(1,2,0)
goniometerbox_items.dlgaddelement(allgoniometerfieldsgroup) return goniometerbox }
// make the bottom box to hold the tilt and the buttons
taggroup makenettiltbox() { taggroup nettiltboxitems taggroup nettiltbox=dlgcreatebox(" Calculate ", nettiltboxitems).dlginternalpadding(0,0)
taggroup nettiltlabel=dlgcreatelabel("Net Tilt / deg") taggroup nettiltfield = DLGCreateRealField(0, 8, 1).dlgidentifier("nettiltfield") taggroup tiltfieldgroup=dlggroupitems(nettiltlabel, nettiltfield).dlgtablelayout(1,2,0).dlgexternalpadding(9,6)
TagGroup CalculateButton = DLGCreatePushButton("Calculate", "calculateangle").DLGSide("Bottom").dlgexternalpadding(8,0) taggroup allnettiltgroup=dlggroupitems(tiltfieldgroup, calculatebutton).dlgtablelayout(2,1,0).dlgexternalpadding(0,0)
nettiltboxitems.dlgaddelement(allnettiltgroup) return nettiltbox }
// Create the dialog
void maketiltdialog() {
TagGroup dialog_items; TagGroup dialog = DLGCreateDialog("Tilt Calculator", dialog_items); dialog_items.DLGAddElement( Maketiltboxes() ) dialog_items.DLGAddElement( Makenettiltbox() )
taggroup tiltlabel=dlgcreatelabel("D. R. G. Mitchell v2.0 Sept 07") dialog_items.dlgaddelement(tiltlabel)
object dialog_frame = alloc(TiltAngleCalculatorClass).init(dialog) dialog_frame.display("Tilt Calculator")
documentwindow dialogwin=getdocumentwindow(0) number xpos, ypos getpersistentnumbernote("Diff Tools:Dialog Positions:Tilt Left",xpos) getpersistentnumbernote("Diff Tools:Dialog Positions:Tilt Top",ypos)
// if the dialog position persistant tags haven't been set // use the default position (bottom left of the application window). If they have been set // both xpos and ypos are not zero, then set the dialog position to that set in the tags
if(xpos>=142 && ypos>=24) { windowsetframeposition(dialogwin, xpos, ypos) }
}
// Invoke the dialog creation function
MakeTiltDialog() |