Forums > MaxMSP

MSD Link Length

October 29, 2009 | 2:58 pm

Hello,

If I have the X,y coordinates for 2 points in a graph (the range of which is -4 to 4) how do I measure the distance between them?

I appreciate that this may be a very simple trig problem but, shamefully, I am useless when it comes to maths. If only someone had explained the wonderful relationship between maths and music when I was at school I would have paid so much more attention!

The Context:

I am using the MSD library. I have created one mass which is attached by an elastic link to another. When one mass moves the other bounces around it thus creating a fun 3D interface. The link position is defined by four values (2 X and 2 Y). I want to use the link length as control data for a parameter on a synth.

I really appreciate any help you can give me with this one. I will say it to save you all the trouble…"I am dim as a bag full of arses for not knowing how to do this".

Nick


October 29, 2009 | 3:02 pm

[quote title=nick williams wrote on Thu, 29 October 2009 14:58]Hello,

The link position is defined by four values (2 X and 2 Y).

^^ Sorry, that should read "(2 PAIRS of X,Y values)" defining the start point and end point of the line on my graph.

Cheers,

Nick


October 29, 2009 | 3:02 pm

[quote title=nick williams wrote on Thu, 29 October 2009 14:58]Hello,

The link position is defined by four values (2 X and 2 Y).

^^ Sorry, that should read "(2 PAIRS of X,Y values)" defining the start point and end point of the line on my graph.

Cheers,

Nick


October 29, 2009 | 3:57 pm

> If I have the X,y coordinates for 2 points in a graph (the range of which is -4 to 4) how do I measure the distance between them?

You should browse Pythagore, and find what is the squared hypothenuse to know it.


October 29, 2009 | 3:57 pm

> If I have the X,y coordinates for 2 points in a graph (the range of which is -4 to 4) how do I measure the distance between them?

You should browse Pythagore, and find what is the squared hypothenuse to know it.


October 29, 2009 | 4:28 pm

if you create a link between your 2 points, you can then use the "get linksLenghts" message to msd ; it will return links lengths = distance between points…

MathieU


October 29, 2009 | 4:28 pm

if you create a link between your 2 points, you can then use the "get linksLenghts" message to msd ; it will return links lengths = distance between points…

MathieU


October 29, 2009 | 6:30 pm

Thank you both for your helpful replies. The "getlinklength" message is exactly what I’m after. I don’t know how I missed that one after studying the help file so much. Doh!

I have been brushing up my trig but clearly have some work to do. Next stop "Squared Hypotenuse"!

Thanks again.

Nick


October 29, 2009 | 6:30 pm

Thank you both for your helpful replies. The "getlinklength" message is exactly what I’m after. I don’t know how I missed that one after studying the help file so much. Doh!

I have been brushing up my trig but clearly have some work to do. Next stop "Squared Hypotenuse"!

Thanks again.

Nick


October 29, 2009 | 6:43 pm

For anybody else that is trying the link length message note that the message must be typed with the incorrect spelling e.g "Lenghts". Thus the correct message is:

"get linksLenghts"

Just to be clear.


October 31, 2009 | 12:08 am

Nice that there’s a function to get it for you, but this is a good one to know anyways… from the days of Pythagoras and probably years before that.

(x1, y1) and (x2, y2) –> your points

differences: (x2 – x1) and (y2 – y1)

square each of these results: (x2-x1)^2, (y2-y1)^2

take the square root of their sum.

so… if your points are (0,0) and (4,3), then the distance is

square root ( (4-0)^2 + (3-0)^2 ), or square root (16 + 9), or 5. yes that was an integer one. Smile

if it all sounds Greek, just do it visually, and turn the sides of your triangle into square grids. it’ll be more clear.

in Max, in expr, with your four points as floats:

expr sqrt ( pow(($f2-$f1), 2.) + pow(($f4-$f3) , 2.) )

i think the syntax is right… yes it does start to look messy, the backslashes are for Max to deal with commas.


Viewing 11 posts - 1 through 11 (of 11 total)