http://imagej.273.s1.nabble.com/Perpendicular-line-selection-tp3693873p3693875.html
variable in length.
> Hi Gabriel,
> The following Tool macro lets you draw L shapes. I adapted it from the
> TiltedRectangleTool macro.
> Sincerely,
>
> Jerome
>
> // L-shape Tool
> //
> // This macro tool draws a L-shape.
> // Click and drag the mouse to set the first segment.
> // After the mouse button is released, drag to set the second segment.
> // Click to finish.
> macro "Tilted Rectangle Tool -C000L1991L91e6" {
> run("Line Width...", "line=1");
> getPixelSize(unit, pixelWidth, pixelHeight);
> getCursorLoc(x, y, z, flags);
> xstart = x; ystart = y;
> x2=x; y2=y;
> while (flags!=0) {
> getCursorLoc(x, y, z, flags);
> if (x!=x2 || y!=y2)
> makeLine(xstart, ystart, x, y);
> x2=x; y2=y;
> wait(10);
> }
> if (x!=xstart || y!=ystart) {
> drawLshape(xstart, ystart, x, y);
> }
> }
>
> function drawLshape(x1, y1, x2, y2) {
> a = atan ((x2-x1)/(y2-y1));
> x3=0;y3=0;
> while (flags==0) {
> getCursorLoc(x, y, z, flags);
> if (x!=x3 || y!=y3) {
> sign=1;
> if (x2>x) sign=-1;
> w=sqrt ((x2-x)*(x2-x)+(y2-y)*(y2-y));
> wsa = sign*w*sin((PI/2)+a);
> wca = sign*w*cos((PI/2)+a);
> makeLine( x1,y1,x2,y2,x2 + wsa,y2 + wca);
> x3=x;y3=y;
> wait(10);
> }
> }
> }
>
> // end
>
>
> On Sun, Feb 1, 2009 at 8:10 PM, Gabriel Landini <
[hidden email]>wrote:
>
>> 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);
>> }
>> -----
>>
>