Get coordinates of points of a square

Hello.
I created a square using - PlaneBufferGeometry.
How can you find out the coordinates of the points of this square? For example, I want to get the coordinate of a point at the bottom left.

You can find these points in BufferGeometry.attributes (in mesh.geometry.attributes.position.array to be precise.)

1 Like

Points in a plane geometry (with segmentation of 1 on width and height) are set in that order:

[0]---[1]
 |  /  |
[2]---[3]

So, if you need coordiantes of point [2], then do something like that:

let g = new THREE.PlaneBufferGeometry(2, 2); // segmentation 1 x 1
let m = _some_material_ ;
let o = new THREE.Mesh(g, m);

let v = new THREE.Vector3();
let pos = geometry.attributes.position;
v.fromBufferAttribute(pos, 2); // now v contains coordinates of point [2]

// and if you want that v in world coordinates
o.localToWorld(v); // now v contains coordinates in world space
1 Like

1 Local space or world space?
2 How was the geometry was constructed?

I’m assuming local and 3JS geometry.

PlaneGeometry( W = 1, H = 1, W_Seg = 1, H_Seg = 1 );
abs [ x, y ] = [ W/2, H/2 ];

[ -1, +1 ] [ +1, +1 ]
          [0,0]
[ -1, -1 ] [ +1, -1 ]

For PlaneGeometry(4,3,2,1) the xy for lower left corner is (-2, -1.5).

Correction was made thanks to mjurczyk.

abs [ x, y ] = [ W*W_Seg/2, H*H_Seg/2 ];
[...]
lower left corner is (-4, -1.5).

Are you sure about these calculations :thinking: ? I may be wrong, but don’t segments adjust to the dimensions (ex. plane (4, 3, n, m) would have corners in (±2, ±1.5), not (±4, ±1.5)) ?

2 Likes

The fun comes, when applied .rotateX[YZ](), or .translate(), or .scale(), or all of them in different order to the geometry :slight_smile:

You are absolutely correct. I was thinking of my own PlaneG Generator not 3JS.