#rotate points/object relative to a center point

1 messages · Page 1 of 1 (latest)

low ravine
#

Hi, I was wondering how I could have objects (in a grid) rotate relative to a center point.

Its a jigsaw puzzle, i'm trying to have piece groups be able to rotate.

I think my issue is i'm trying to do it without storing a "real" x,y offsets for each piece (to apply rotation upon)

I feel like the way I went about it falls apart because I try (and fail) to generate the current offsets based on the current positions and apply rotation to it and it doesn't work. (the relative distances do, but are not synced to the right angles, in fact it feels random)

static rotate_angle = function(_angle)
    {
        var _origin_x = x,
        _origin_y = y;
        for (var i = 0; i < array_length(pieces); i++)
        {
            
            var _dist = point_distance(_origin_x, _origin_y, pieces[i].x, pieces[i].y);
            var _pdir = point_direction(_origin_x, _origin_y, pieces[i].x, pieces[i].y);
            var offset_x = lengthdir_x(_dist, _pdir),
                offset_y = lengthdir_y(_dist, _pdir);
            
            pieces[i].x = x + lengthdir_x(offset_x , angle) + lengthdir_x(offset_y , angle - 90)
            pieces[i].y = y + lengthdir_y(offset_x , angle) + lengthdir_y(offset_y , angle - 90)
        }
    }

Please help, thanks!

spring junco
#

Could you post some screenshots of what you’re seeing and sketches of what you’re hoping to see maybe? Might help to clarify the problem. One potential issue is that you’re passing “_angle” to that function but using “angle” (without an underscore) in the last few lines

low ravine
#

Hi, thanks for the response. the angle/_angle is not the issue (although, nicely spotted)
I added of gif of how it currently behaves. the angle is written on the squares. As you can see, its a bit random and the positioning doesn't reflect the angle even if it sometimes gets it right.