I have a set of points (vertices), and I need to write code that will calculate the position of each vertex separately relative to the rotation.
So far, I have managed to achieve the possibility of rotation on only one axis. But I don’t understand how it can be rotated on all axes.
local Vertices = script.Parent --verts folder
local Circle = math.pi * 2
local StartPoses = {}
for i, vertex in Vertices:GetChildren() do --Save a start position
if vertex:IsA("Part") then
StartPoses[vertex.Name] = vertex.Position
end
end
while true do
for i = 1, 360, 1 do task.wait()
angleY = math.rad(i)
for i, vertex in Vertices:GetChildren() do
if vertex:IsA("Part") then
local x = StartPoses[vertex.Name].X
local z = StartPoses[vertex.Name].Z
local cos = math.cos(angleY)
local sin = math.sin(angleY)
local new_x = x * cos - z * sin
local new_z = x * sin + z * cos
vertex.Position = Vector3.new(new_x, StartPoses[vertex.Name].Y, new_z)
end
end
end
end
I can’t use this, because this system will then be integrated for EditableMesh where vertexes don’t have a Cframe. it also does not solve the problem that so far it can only rotate on one axis.
You should give @dthecoolest’s response a bit more looking into, because he’s giving you the best way to do it, and it’s correct and able to rotate around any axis. Vertices don’t have CFrames, but you can transform their positions with CFrames. If your mesh vertices are not already at the world-space origin (or centered around the point you wish to rotate about), you can move them there, rotate about the origin, move them back to their world-space center.