Last active
May 17, 2023 21:36
-
-
Save SigmaThetaTech/d37273a20bd7305bad56863bb1f29bd5 to your computer and use it in GitHub Desktop.
Helper functions for conversion of spherical to rectangular coordinates and plotting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
SPHERICAL TO RECTANGULAR COORDINATES | |
This algorithm takes sphereical coordinates, which are helpful for defining spray patterns at a defined radius relative to the shooter, | |
and converts them to cartesian coordinates that Roblox can easilly understand and plot. | |
(https://www.mathworks.com/help/symbolic/transform-spherical-coordinates-and-plot.html) | |
Illustrations: | |
https://gyazo.com/bc7e68c8874bd063f76a2e72263f1109 | |
https://gyazo.com/2abe1234d04ed51eb1df045b36d59f0d | |
]] | |
-- USE THE RIGHT THUMB RULE! | |
-- Use your right thumb to point in the positive direction of an axis | |
-- The direction of your fingers is the direction of positive rotation. | |
local RHO = 5 -- Radius | |
local PHI = math.rad(30) -- Pitch (Z-Axis Angle) | |
local THETA = math.rad(0) -- Yaw (Y-Axis Angle) | |
function sphericalToRectangular(rho: number, phi: number, theta: number): Vector3 -- (Radius, Pitch, Yaw) | |
local rectangularCoordinate = Vector3.new( | |
rho * math.sin(phi) * math.cos(theta), | |
-rho * math.cos(phi), | |
-rho * math.sin(phi) * math.sin(theta) | |
) | |
return rectangularCoordinate | |
end | |
function plot(pos) | |
local newBrick = Instance.new("Part") | |
newBrick.Size = Vector3.new(0.1, 0.1, 0.1) | |
newBrick.Anchored = true | |
newBrick.BrickColor = BrickColor.Red() | |
newBrick.Position = pos | |
newBrick.Parent = game.Workspace | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The conversions were redone for Roblox's weird -Z axes and stuff.