Need help or advice ? Come to the Icy club ! - Every Wenesday morning from 9h30 to 12h30 - Francois Jacob Building - Main hall - Pasteur
Register

Angles Along Polyline

by tprovoost / Thomas Provoost

Displays the value of the angles along a polyline ROI.

version 1 (last version):

download to use and modify in Icy. How do I use scripts ? A Problem ? ask the community.
Changelog for this version: initial version
/* From:
 * http://stackoverflow.com/questions/6719563/compute-the-angle-of-a-triangle-when-3-points-are-given
 */

importClass(Packages.icy.sequence.Sequence)
importClass(Packages.icy.roi.ROI2DPolyLine)

seq = getSequence()
if (seq == null) throw "Please open a sequence first!"

roi = seq.getSelectedROI2D()

if (roi == null || !(roi instanceof ROI2DPolyLine)) throw "Selected ROI is null or not a polyline."

list = roi.getPoints() // get the list of points

// generate arrays of x and y values for simpler manipulations
x = []
y = []
for (i = 0; i < list.size(); i++) {
	x[i] = list.get(i).x
	y[i] = list.get(i).y
}

// calculates the dot product
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 = Math.sqrt((x[i - 1] - x[i]) * (x[i - 1] - x[i]) + (y[i - 1] - y[i]) * (y[i - 1] - y[i]));
	len2 = Math.sqrt((x[i + 1] - x[i]) * (x[i + 1] - x[i]) + (y[i + 1] - y[i]) * (y[i + 1] - y[i]));

	angle = Math.acos(dotprod / (len1 * len2)) * 180 / Math.PI;
	println(i + ":" + angle);
}

This script has no documentation. A Problem ? ask the community.



Icy script publication Id : P2F3B5