Random Vector Position Help

I have literally no idea HOW to do this, but I know WHAT I’m trying to do:

  1. Calculate a 2-dimensional circular plane with a set radius around a part.
  2. Mathematically calculate a completely random vector within the circular plane.

How do I even begin this?

If you have a circle radius R you can draw it by using the parameterization of a circle.
Where T is time and constrained to 0 < T < tau

(cos(T) * R, sin(T) * R)

If you’re unsure where this comes from then you can take a quick look at any circle and draw a right triangle within this circle. I’m not the best artist but here is a depiction.

image

If you have a right triangle whose hypotenuse is the radius of the circle, then you can solve for y and x using cosine and sine. SOH CAH TOA

Here is a desmos page I setup that you can play with:

a controls the domain of t to show a specific region of the circle
r controls the radius

If you wanted to generate a vector with length R pointing in a random direction inside this circle you can just generate a random number between tau and 0

local Radius = 10

local RandomAngle = math.random() * math.pi * 2
local RandomVector = Vector2.new(
    math.cos(RandomAngle) * Radius,
    math.sin(RandomAngle) * Radius
)
3 Likes