Perpendicular line selection
Posted by Gabriel Landini on Feb 01, 2009; 7:10pm
URL: http://imagej.273.s1.nabble.com/Perpendicular-line-selection-tp3693873.html
Hi,
I have been trying to create an "L" shaped line selection, so one clicks and
while dragging the selection is a line (from the originally clicked point to
the current cursor position, just like a normal line selection), but with a
perpendicular short line at the end of it.
The macro below makes the line OK, but I cannot get the small perpendicular
segment working.
2 lines are perpendicular if the product of their slopes is -1, but I am
obviously missing something very badly as the snippet below does not work.
Two lines near the end of the function phi (with comments) are the culprit.
Note: if you run the macro, it should be stoppable with the escape key, but
for some reason sometimes it does not under linux, so please do not run this
while you have some important stuff in other IJ windows just in case.
Can anybody give any clues?
Many thanks in advance
Gabriel
------
id=getImageID;
run("Select None");
w = getWidth;
h = getHeight;
while (true){
getCursorLoc(x, y, z, flags);
xstart = x;
ystart = y;
x2=x;
y2=y;
while (flags&16 !=0) {
getCursorLoc(x, y, z, flags);
if (x!=x2 || y!=y2) phi(xstart, ystart, x, y);
x2=x;
y2=y;
wait(10);
}
}
print ("Done!");
function phi(x0,y0,x1,y1) {
d = sqrt((y1-y0)*(y1-y0)+(x1-x0)*(x1-x0));
xa = newArray(floor(d) +1);
ya = newArray(xa.length);
dx=x1-x0;
dy=y1-y0;
for (i=0;i<xa.length;i++) {
xa[i]=x0+i*dx/d;
ya[i]=y0+i*dy/d;
}
xa[xa.length-1]=xa[xa.length-1]+15*(-1/(dy/d)); // here is one error
ya[xa.length-1]=ya[xa.length-1]+15*(-1/(dy/d)); // here is the other
makeSelection("freeline",xa,ya);
}
-----