Spatial relationship

Among

Tap or click anywhere to send the moving circle toward that point. It is among the group when it sits near the cluster center.

Fig. 1 Group proximity — mover is among the cluster when near its center

Try it — drag, click, or tap inside the figure.

Open in p5 Web Editor Fork and experiment with this sketch

Concept

AMONG means within a group of three or more things. Unlike between (two endpoints), among depends on proximity to several neighbors or to a group region.

Translation strategy

Ways to express among in a sketch:

  • Group center: Compare distance to the average position of the group
  • Neighbor count: Count how many members fall within a radius
  • Bounding region: Test membership inside a hull or box around the group
Key p5.js methods
Key methods

Canvas coordinates
createCanvas() — origin (0, 0) is top-left
• Y increases downward; X increases to the right

Group math
dist() — proximity to center or members
• Arrays — store many reference positions

Drawing
ellipse() — group members and mover

Pointer input
mousePressed() — start motion or set a target
mouseX, mouseY — click position
Code pattern
Code pattern

1. Define the group
let group = [{x:100,y:100},{x:200,y:120},{x:150,y:180}];

2. Find the center
let cx = group.reduce((s,p)=>s+p.x,0)/group.length;
let cy = group.reduce((s,p)=>s+p.y,0)/group.length;

3. Test membership
let d = dist(mover.x, mover.y, cx, cy);
let isAmong = d < groupRadius;

4. Move toward a click
targetX = mouseX; targetY = mouseY;