I’ve been working on a color wheel for the past few hours, and have really great progress so far:
I’m successfully able to, given the X and Y of the mouse in the local space of the wheel, solve for the Hue and Saturation as follows:
-- mid = midpoint of the circle (also the radius)
-- dist = distance from the mouse to the midpoint
local hue = (math.pi - math.atan2(y - mid, x - mid)) / (math.pi * 2)
local sat = dist / mid
This works super well, my issue comes in that I now have to go the reverse way: Solve for an X and Y given a Hue and Saturation.
Here are my algebra steps to solve down the original hue equation for the angle:
.1) h = (π - arctan(a)) / (2π)
.2) 2πh = π - arctan(a)
.3) 2πh - π = -arctan(a)
.4) π - 2πh = arctan(a)
So I’ve arrived at where I would reverse the arctan
, and normally I would take the tan
of both sides. I tried this and got really undesirable numbers.
I believe I’m left with two options, either my algebra is wrong (which is totally possible), or the atan2
function does more under the hood than just an arctan
which I need to account for in my equation, which I think is the more likely option but I don’t really know. So now I ask for help, how should I solve for a
? And overall, what else should I know to solve for x
and y
given a
?