Posted by
kelpny on
Feb 18, 2019; 5:39am
URL: http://imagej.273.s1.nabble.com/Measure-of-the-angles-of-a-segmented-line-tp5001041p5021812.html
I am trying to adapt Wayne's code to fit my use but am new to writing code.
My goal was to get the angle and length of the first line of the first angle
recorded in the results table along with the slice number which I was able
to to with the code below...although this gives me all the numbers I need it
does give me *too much* information and would be easier if I could just have
certain parts of the data recorded.
For example: Using a 5 point segmented line (4 total lines)
1. adds length of line 1 and 2=total length
2. gives just the angle between line 2 and 3
3. and gives length of line 4
4. All within 1 row of the results table
Current Code:
macro "Segmented Line Angles [a]" {
getSelectionCoordinates(x, y);
for (i=1; i<x.length-1; i++) {
dotprod = (x[i+1]-x[i])*(x[i-1]-x[i])+(y[i+1]-y[i])*(y[i-1]-y[i]);
len1 = sqrt((x[i-1]-x[i])*(x[i-1]-x[i])+(y[i-1]-y[i])*(y[i-1]-y[i]));
len2 = sqrt((x[i+1]-x[i])*(x[i+1]-x[i])+(y[i+1]-y[i])*(y[i+1]-y[i]));
angle = (180/PI)*acos(dotprod/(len1*len2));
slice = getSliceNumber();
row = nResults();
setResult("Angle", row, angle);
setResult("Length", row, len1);
setResult("Slice", row, slice);
updateResults();
After Running :
<nabble_img src="2_line.png" border="0"/>
--
Sent from:
http://imagej.1557.x6.nabble.com/--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html