How to find point on a circle using a angle

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stevepetoskey

The way I am currently using is the “Unit Circle” aka

posOnCircle = vector2(offset + radius * cos(angle), offset + radius * sin(angle))

The problem is this only works using degree calculations, which Godot does radian by standard. So I was wondering if there is a better way to do this with Godot, or at least how to make Godot calculate in degrees not radians.

Note: If you’re generating random points on a circle, you may want to support this proposal.

Xrayez | 2020-11-12 22:45

:bust_in_silhouette: Reply From: jgodfrey

You can easily convert between degrees and radians at will via the following 2 utility functions:

var rads = deg2rad(deg)
var degs = rad2deg(rad)

Yeah I tried that, but where would I put the rad2deg() in the equation

offset + r*cos(θ)

Because on a calculator in degrees mode, 0+1cos(30) = 0.8660254038
But on Godot, rad2deg(0+1cos(30)) = 8.837957

Thank you in advance

stevepetoskey | 2020-11-10 19:27

Godot’s sin() and cos() functions expect radians. If the value you have is in degrees you’d want to convert that to radians prior to passing it to the cos/sin functions.

So, this:

cos(deg2rad(angle_in_degrees))

For example, this:

print(cos(deg2rad(30)))

Outputs this:

0.866025

jgodfrey | 2020-11-10 19:36

Thank you! It works now

stevepetoskey | 2020-11-10 19:42