 # Measuring a polygon selection all segments length and angle or all vertex coordinates

I need the geometry from a marked polygon, e.g. all vertex coordinates or a reference vertex and polygon segment’s length and angle.

Any reference to a plugin or example is appreciated.

2 Likes

Hello Klas -

Provided your “marked polygon” is packaged as a PolygonRoi,
you can query the `PolygonRoi` for its vertices.

Here is a jython (python) script that demonstrates this:

``````from ij.gui import Roi
from ij.gui import PolygonRoi

roi = PolygonRoi ([135, 160, 110], [110, 160, 160], Roi.POLYGON)
print  roi
print  roi.getXBase()
print  roi.getXCoordinates()
print  roi.getYBase()
print  roi.getYCoordinates()
``````

Note that the `PolygonRoi` vertices, as returned by
`getXCoordinates()` and `getYCoordinates()`, are relative
to the upper left corner of the `Roi`, as returned by `getXBase()`
and `getYBase()`.

Thanks, mm

1 Like

getSelectionCoordinates(xpoints, ypoints)
Returns two arrays containing the X and Y coordinates, in pixels, of the points that define the current selection. See the SelectionCoordinates macro for an example. See also: selectionType, getSelectionBounds.

``````newImage ("hexagons", "8-bit ramp", 512, 512, 1);
//setTool("polygon");
run("Select None");
makePolygon(89,72,278,153,181,219,250,299,84,321,217,53);
// These macros demonstrate how to use the
// getSelectionCoordinates function.
macro "List XY Coordinates" {
requires("1.30k");
getSelectionCoordinates(x, y);
for (i=0; i<x.length; i++)
print(i+" "+x[i]+" "+y[i]);
``````

@Mountain_man and @Mathew thanks for your suggestions. I will try them out.
/Klas