What does the PointToObjectSpace() really do?

I saw this in many systems that includes the mouse Position. For example, a grid placement system. But for some reason I never really understood the meaning of it. I know that object space means that the origin and coordination depends on the object its self, unlike world space. Mostly this function would run on a CFrame and in the parameters, their would be a mouse position which doesn’t make sense to me. I looked it up and saw no results. If anyone could help me it would be much appreciated.

1 Like

image

imagine that the coordinates of the world is black and the coordinates of the object is red. P is at (x0, y0). What PointToObjectSpace() does is convert the coordinates of P from (x0,y0) to (x1,y1) as if the object were the centre of the world.
The main reason for doing this is that the calculations are usually simpler after doing this transformation. Then usually PointToWorldSpace() is done which is the reverse process.

4 Likes

well basically it means, what would the position of this point be if we make this Object to be 0,0,0 and reset the rotation.
the equation for it is CFrame:Inverse()*OtherCFrame
on a 2d grid the object is rotated 90 degrees to the right and is on (1,-1)
say the point is at 2,8)

POINTtoOBJECTspace would be (9,-1)

image
so your telling me that the distance between (1,-1) and (2,8) while (1,-1) is rotated 90 degree to the right would be (9,-1) relative to point (1,-1)? Is that how object space work???

I sort of messed up. to reverse a right you need to make a left. so (2,8)-(1,-1) would be (1,9) and rotating it to the left would be (-9,1)
blue lines is correcting it to 0,0 and the purple line is fixing the rotation


this image was made in desmos

this is just on 2d 3d uses matrices instead of the trigs I used in the photo.