Re: Measure of the angles of a segmented line
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
URL: http://imagej.273.s1.nabble.com/Measure-of-the-angles-of-a-segmented-line-tp5001041p5001045.html
On Dec 5, 2012, at 8:23 AM, Eric Denarier wrote:
> Hi all,
> Is there a macro/plugin to measure all the angles formed by a segmented
> line selection ?
Here is a macro that does this:
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));
print(i, angle);
}
I found the code for calculating an angle given 3 points using the dot product at
http://stackoverflow.com/questions/6719563/-wayne
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html