Angles and distances calculation in multipoint tool

Hi There

I am analyzing the location of a Point C relative to two points A and B. I would like to describe location C by the distance from B and the angle between a Vector AB and BC.

With the measurement tool its easy to measure the distances.
With the angle measurement tool its easy to measure the angles.

But I am looking for the most reproducible, the easiest way to do all the steps with the multi-point tool. As the multipoint tool gives me coordinates of all the points, I think it should be possible to have the distances and the angles calculated as well - based on the coordinates of A, B, C.

Thank you very much for your highly appreciated help!
Stefan

Stefan,

this is easily possible with a little ImageJ-macro.

The mathematics are basic and I guess you know how to do the calculation.

Remains the problem of getting the coordinates of the three points that you’ve set by hand with the multi-point tool:

Here is one approach

getSelectionCoordinates(X, Y);
Array.show("x,y-coords", X, Y);

and here is another

run("Set Measurements...", "centroid redirect=None decimal=0");
run("Measure");

Paste either of the above macro code lines to an empty macro window (Plugins >> New >> Macro) and run it after you’ve set the selection points to an image.

Regards

Herbie

1 Like

Hi Herbie
Thank you for your quick response. I tried the macro but did not get the desired result. Please find a screenshot attached. for clarification

So what I am looking for is

Distance 1-2
Distance 2-3
The angle between lines 1-2 and 2-3

Thank you so much for your help!
Stefan

Did you read my previous post?

The mathematics are basic and I guess you know how to do the calculation.

What you need is basic trigonometry in the plain, i.e. basic highschool knowledge that is of course also available from the Web.

I’m sure you solve this problem in 10 minutes—no?

Remains the problem of getting the coordinates of the three points that you’ve set by hand with the multi-point tool:

So what I did is help you with this question because it is ImageJ-related.

Regards

Herbie

PS:
Because it is advent season:

// imagej-macro "lawOfCosines" (Herbie G., 15. Dec. 2018)
requires( "1.52i" );
getSelectionCoordinates(x, y);
if (x.length!=3) exit("Incorrect number of point selections!");
g=fromCharCode(947); d=fromCharCode(176);
aSqr=lenSqr( x[0], y[0], x[1], y[1] );
bSqr=lenSqr( x[1], y[1], x[2], y[2] );
cSqr=lenSqr( x[0], y[0], x[2], y[2] );
a=sqrt(aSqr);
b=sqrt(bSqr);
gam=180*acos((aSqr+bSqr-cSqr)/(2*a*b))/PI;
print("AB = "+a+"; BC = "+b+"; "+g+" = "+gam+d);
exit(); // gamma is the angle at point B
function lenSqr( x_0, y_0, x_1, y_1 ) {
   return ( pow( x_0 - x_1, 2 ) + pow( y_0 - y_1, 2 ) );
}
// imagej-macro "lawOfCosines" (Herbie G., 15. Dec. 2018)

Don’t forget to mention in reports, theses, or publications that you’ve received help!

Ha! Thank you Herbie… HighSchool has been quiet a while, so I am really grateful for your help with the Math.

I don’t want to bother you with basic math :slight_smile: or my lack of understanding of the same. But would it be possible to adapt your macro in a way that the angle is always measured clockwise instead of just the larger angle opening up between those lines? This would be easier for the unambiguous assignment of one specific location of the lesion being it on the super or lower hemisphere.

From the image you’ve posted, I conclude that your work has a scientific background, thus I don’t understand why it matters when you received your education. Mathematics is basic to all kinds of so-called exact sciences and the Law of Cosines is terribly basic and can be looked up in many places, e.g. here: https://en.wikipedia.org/wiki/Law_of_cosines.
It remains the question, why you didn’t want to do that.

Regards

Herbie

I don’t want to bother you with basic math

Please understand that we are here to help, not to do your work; and you’ve received quite some help already.

in a way that the angle is always measured clockwise

There is no clockwise or counter-clockwise for an angle between two line-elements that form an apex.

My macro computes the acute angle. If you prefer the complement, you need to subtract the acute angle from 360 deg, but I think that this operation is not the problem you like seeing solved …

If you mean the clockwise angle depending on the order in which the points are set, then you need a vectorial approach that requires a completely different macro code. It is basic as well and is left as an exercise to you.

Regards

Herbie

Hey there, if you want to say whether the lesion (3) is located in the upper of lower half of the fundus, you simply compare the y-coordinate of the lesion (3) with the y-coordinate of the optic nerve (1) and the fovea (2). In your example, y3<y1 and y3<y2, consistent with the lesion (3) being in the superior half. This is much simpler than messing with the angle. Regards, David