Short Description

Displays the value of the angles along a polyline ROI.

Versions

  • Version 1 • Released on: 2013-03-11 11:52:44
    Download
    Description:

    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);
    }

Leave a Review