draw lines between separated points from a specific distance

Zoy's icon

Hello Folks !

I'm trying to draw segments between points that are separated by a specific maximum distance
Basically I start from a 3D random distribution of points, and I want to that if among them some are close enough (below a fixed length) a segment is drawn between those points.

For the moment I just can draw segment between points in the order they are in the matrix...... I think I can obtain the distance between all the points with jit.gen but I don't know how to use the condition of a maximum distance in order to make appear lines between the points.

Have you an idea ?

Thanks !

ANIM_SEGMENTS2.maxpat
Max Patch
ANIM_SEGMENTS21.maxpat
Max Patch
Andro's icon

Not behind the computer so i cant check your patch but you could try an equation which calculates the distance between two points in 2d or 3d space ( theyre in the forum with the expr object) then put this into an if object.
If $1 < 2 then 1 else 0. ( if distance is less than 2 then output 1 ) This output could be used to create a bang to make a connection.

Zoy's icon

Hey thanks Andro !
Here is a new patch that is working with 2 points ; now I want to do the same but with as many points as wished. And it seems very difficult to me because in one hand I need to calculate the distance of all possibles pairs of points (and I don't know how to do this) and in other hand I don't think the way I use to draw the line is good in this case...

ANIM_SEGMENTS3.maxpat
Max Patch
Zoy's icon

a better patch here (for 2 points only) :

ANIM_SEGMENTS31.maxpat
Max Patch
deligut's icon

Maybe like this?

Matrix-manipulation-2.maxpat
Max Patch
Zoy's icon

Hi thanks Deligut ! Here are the points just linked by pairs, and I want that every points can be connected to each other below a specific distance.
Since I do the first post I have found a good illustration of want I want to succed : http://threejs.org/examples/#webgl_buffergeometry_drawcalls (select the buffergeometry_drawcalls tag).
I wrote an other patch that give me the distance between each point but it do that not simultaneously for every particles then draws lines successively.

ANIM_SEGMENTS4.maxpat
Max Patch
Jonas Magnussen's icon

Hi Zoy.

C'74 on instagram recently retweeted a project done by Federico Foderaro which seems to do exactly what you want your patch to do. I fiddled with a couple of your patches, and might have thought of a solution. I think the best way to execute this would be to draw X amount of objects in jit.gl.sketch at any given time (will be equal to the number of points being under minimum distance away from each other). I have attached a little sketch patch, just to demonstrate that you can have several independent lines drawn at the same time, just in case it isn't already obvious to you (if so, sorry for stating the obvious!). Obviously it's nowhere near the end result yet.

Say we solve this by drawing multiple objects in jit.gl.sketch, these lines will be defined in space by using two vertexes, and a coordinate for each of them. I'm not sure wether the coordinate system in jit.gl.sketch is "in sync" with the values we get from jit.noise, but say they are (if they are not, we probably just need to do some scaling), we can get the coordinate for each point, and draw a line to another coordinate/point if the distance is under a certain amount! I'm not that good with math, so I would need help finding the distance between two different coordinates in three dimensional space. You already did something similar in your last patch, so the solution shouldn't be far away, no?

Max Patch
Copy patch and select New From Clipboard in Max.