Login  Register

Re: measuring distance along a line at a set angle

Posted by jmutterer on Feb 06, 2009; 10:17am
URL: http://imagej.273.s1.nabble.com/measuring-distance-along-a-line-at-a-set-angle-tp3693828p3693831.html

Dear Connor

In this new version of the Fixed angle line tool macro, you can grab the end
point of an existing line and extend it while keeping it at the same angle.
You have to grab within 5 pixels from the end point to catch it. Still use
the tool's option dialog or 'alt' key while dragging to change the angle,
and the 'shift' key to measure the line. I also replaced the 'pi' variable
by the built-in PI token as pointed out by Gabriel.
Sincerely,
Jerome

// Fixed Angle Line Tool Macro
var a=0;
var leftClick=16;
var x1,y1,x2,y2;
macro 'Fixed Angle Line Tool - C000L05f0L0af5' {
getCursorLoc(x, y, z, flags);
getLine(x1, y1, x2, y2, lineWidth);
if ((x2-x)*(x2-x)>25||(y2-y)*(y2-y)>25) { x1=x;y1=y;}
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


On Fri, Feb 6, 2009 at 9:37 AM, Gabriel Landini <[hidden email]>wrote:

> Hi Jerome,
>
> On Thursday 05 February 2009 23:31:43 you wrote:
> > // Fixed Angle Line Tool Macro
> > var a=0;
> > var pi=3.1415926535;
>
> Just a detail. There is a (perhaps undocumented?) system variable in the
> macro
> language (PI) which stores the value of pi.
>
> You can test this:
>
> write (PI);
>
> Not that is saves any computation time, but it is quite convenient, so one
> avoids using different approximation of pi across different procedures.
> Cheers,
>
> Gabriel
>