Holding constant angle while using line tool

imagej

#1

I’m measuring some distances on ImageJ but I either want to hold the line angle at 0 degrees or 90 degrees. Is there a way to set a constant line angle?


#3

@Ecg, glad your problem is solved! Do you mind posting the URL to the macro so that others having the same issue can also solve it?


#4

Sure thing!
The following tool macro allows you to draw lines with constant angle. To
change this angle, open the tool’s options dialog by double clicking on the
tool icon, or adjust the angle manually by pressing the ‘alt’ key while
dragging the mouse. Also while dragging, the ‘shift’ key will measure the
current line.

// Fixed Angle Line Tool Macro 
var a=0; 
var pi=3.1415926535; 
var leftClick=16; 
macro 'Fixed Angle Line Tool - C000L05f0L0af5' { 
getCursorLoc(x1, y1, z, flags); 
while (true) { 
  getCursorLoc(x2, y2, z, flags); 
  if (flags&leftClick==0) exit(); 
  if (x2!=x1 || y2!=y1) { 
    dx=(x2-x1); dy=(y2-y1); 
    if (isKeyDown('alt')) { 
      makeLine(x1,y1,x2,y2); 
      a=atan2(dy,dx); 
    } else if (isKeyDown('shift')) { 
     run ('Measure'); 
    } else { 
    d=sqrt(dx*dx+dy*dy); 
      makeLine(x1,y1,x1+d*cos(a),y1+d*sin(a)); 
    } 
  } 
  wait(10); 
} 
} 

macro 'Fixed Angle Line Tool Options' { 
da=180*a/pi; 
da=getNumber("fixed angle",da); 
a= pi*da/180; 
} 

// end