measuring distance along a line at a set angle

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

measuring distance along a line at a set angle

connor
hello

i need to measure a series of distances from a set point at various angles. is there a way using imagej to specify a point from which a line tool measurement should begin, and then set the angle at which the line should extend but still be able to manually manipulate the distance (something like how holding shift fixes the line at either 90 or 0 degrees but still allows you to change its length)? i'm new to imagej so this might be a fairly obvious question, but i haven't been able to find any documentation about it, nor any previous threads on the topic.

thanks for your help!

connor
Reply | Threaded
Open this post in threaded view
|

Re: measuring distance along a line at a set angle

jmutterer
Dear Connor,
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.

Jerome

// 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

On Thu, Feb 5, 2009 at 12:37 AM, connor <[hidden email]> wrote:

> hello
>
> i need to measure a series of distances from a set point at various angles.
> is there a way using imagej to specify a point from which a line tool
> measurement should begin, and then set the angle at which the line should
> extend but still be able to manually manipulate the distance (something
> like
> how holding shift fixes the line at either 90 or 0 degrees but still allows
> you to change its length)? i'm new to imagej so this might be a fairly
> obvious question, but i haven't been able to find any documentation about
> it, nor any previous threads on the topic.
>
> thanks for your help!
>
> connor
> --
> View this message in context:
> http://n2.nabble.com/measuring-distance-along-a-line-at-a-set-angle-tp2272390p2272390.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: measuring distance along a line at a set angle

connor
thanks a lot jerome! this is exactly what i was looking for. one useful feature that i might try to add once i get some more macro programming under my belt is to allow you, like the line tool, to grab the ends of the line once it's been placed and continue to adjust the length without changing the angle. if it had this feature you could use the next image function, and adjust the line while still maintaining the angle and starting point.

thanks again!

connor

jerome mutterer-2 wrote
Dear Connor,
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.

Jerome

// 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

On Thu, Feb 5, 2009 at 12:37 AM, connor <oozie.nelson@gmail.com> wrote:

> hello
>
> i need to measure a series of distances from a set point at various angles.
> is there a way using imagej to specify a point from which a line tool
> measurement should begin, and then set the angle at which the line should
> extend but still be able to manually manipulate the distance (something
> like
> how holding shift fixes the line at either 90 or 0 degrees but still allows
> you to change its length)? i'm new to imagej so this might be a fairly
> obvious question, but i haven't been able to find any documentation about
> it, nor any previous threads on the topic.
>
> thanks for your help!
>
> connor
> --
> View this message in context:
> http://n2.nabble.com/measuring-distance-along-a-line-at-a-set-angle-tp2272390p2272390.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: measuring distance along a line at a set angle

Gabriel Landini
In reply to this post by jmutterer
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
Reply | Threaded
Open this post in threaded view
|

Re: measuring distance along a line at a set angle

jmutterer
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
>