I have a plugin, GUI Studio, and I want to add support for rotated GUIs. Right now, I'm trying to position pseudo-resize handles (just other GUIs) on the left/top/bottom/right sides of the GUI no matter it's rotation.
I will present the Left handle code. The issue I am having is that it is slightly below the center of the left side (imagine the left side of a GUI and it rotated and now imagine where you could see a resize-handle at the center of that side). It's not there, and always ends up slightly below the correct point.
Here is how I find the direction from the rotation
function GetGuiDirection(x, gui)
local rotation;
if x == "Left" then
rotation = math.rad(gui.Rotation+270)
elseif x == "Top" then
rotation = math.rad(gui.Rotation)
elseif x == "Right" then
rotation = math.rad(gui.Rotation+90)
elseif x == "Bottom" then
rotation = math.rad(180+gui.Rotation)
end
return Vector2.new((math.sin(rotation)), (math.cos(rotation)))
end
And here is how I am positioning the LEFT resize handle:
local left_direction = GetGuiDirection("Left", gui_x)
local solvedx = ((posx+sizex/2)-rhandle.AbsoluteSize.X) + ((sizex/2) * left_direction.x)
local solvedy = ((posy+sizey/2)-rhandle.AbsoluteSize.Y/2) - ((sizex/2) * left_direction.y)
print(((posy+sizey/2)-rhandle.AbsoluteSize.Y/2), " - ", ((sizex/2) * left_direction.y))
left.Position = UDim2.new(0,solvedx,0,solvedy);
Just notice that the math in the first set of parenthesis on the solve_ variables is just to get the center of whatever GUI is currently selected. In general, everything is correct and it gets positioned in the same relative-coordinates no matter the rotation/size. It's just that it is slightly below (on the Y axis) where it should be.
Does anyone have any experience with this sort of math and can explain a solution - or the problem?

17 comments
The results I'm getting are not very close to the center of any of the edges using your code. With the Y value being the most "off."
My bad. The X coordinate seems rather fine (mine was as well); but, again like mine, the Y coordinate is very off.
How are you using my code? I'm getting the center of the edge each time I call the function.
UDim2.new(0,centerofedge.x-rhandle.AbsoluteSize.X/2,0,centerofedge.y-rhandle.AbsoluteSize.Y/2); -> As the GUI's size increases, the accuracy of the Y coordinate decreases. What factor am I missing?
Ah yes... I was testing my code on a square. I should have tested it on a rectangle. I see what's going on. I'll try to figure it out.
I have fixed it, and edited my answer accordingly.
Heh....I still regret to say that I am getting the exact same result as my code gave me. The position of the handle (I am testing the left face) is still slightly below where it show be. Could this be a rounding error or something similar?
Here (http://i.imgur.com/lnH7IgW.png) is an image of what is happening (only pay attention to the left-side handle at the moment)
Is your image centered?
Yes. I have actually found a temporary solution of adding/subtracting (depending on which handle) 5 pixels. Works flawlessly. I just don't know where the 5 pixel amount comes from. The image is centered and takes up the entire canvas.
I lied :( It only worked when the GUI rotation was < 90 or >-90
I tried the code and I got this. I used handle.Position = UDim2.new(0, centerOfEdge.x - handle.AbsoluteSize.x/2, 0, centerOfEdge.y - handle.AbsoluteSize.y/2); too. Maybe you're doing something with the result that is changing the way it looks for you.
Have you tried using your code at 90 degrees? (http://i.imgur.com/EY1EzLl.png?1) I am adjusting nothing and using the exact code you gave me this time.
I'm to the point where I'll go ahead and give you the whole RBXM plugin if you think you could fix it. This issue is beyond my frustration threshold.
I tried it at 90 degrees http://imgur.com/M0I7Toy
I quit
frickedy frick stephan. Why cant anyone talk to you D: