Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I get CFrames in a circle around a certain point with equal distance between them?

Asked by 5 years ago

As the title says I need to find points circled around a point on a certain distance between the main point. So for example if you want to position your parts around the main part you would want to take the parts CFrame and then multiply it by CFrame.new(5,0,0),CFrame.new(-5,0,0),CFrame.new(0,0,5),CFrame.new(0,0,-5). If I want to add another point In between two other points I set the parts CFrame to the x/2 one of the first and z/2 of the second. But this way I will have to script everything manually because while some points have changed X's while others have changed Z's and I cant do it as many times as I want. Any help wil be appreciated.

1 answer

Log in to vote
0
Answered by
fredfishy 833 Moderation Voter
5 years ago

Look up parametric circle equations, but the jist of it is basically

x = sin(t) * radius
y = cos(t) * radius

or

x = cos(t) * radius
y = sin(t) * radius

So, you could do something like

function getPoints(pointsAroundCircle)
    divisor = pointsAroundCircle / 2
    points = {}
    for i = 1, math.pi * 2, math.pi/divisor do
        x = cos(i) * radius
        y = sin(i) * radius
        table.insert(points, {x, y})
    end
    return points
end
Ad

Answer this question