# Undoing a mathematical expression

In my color wheel I am converting mouse-pos relative to the wheel into color.

``````local h = (math.pi - math.atan2(ColorPickCenter.Y - Center.Y, ColorPickCenter.X - Center.X)) / (math.pi * 2)
local s = (Center - ColorPickCenter).Magnitude / (ColorWheel.AbsoluteSize.X/2)
``````

Although, I am trying to convert this color back into position. I tried

``````local undoH1 = math.cos((math.pi + h) * (2 * math.pi))
local undoH2 = math.sin((math.pi + h) * (2 * math.pi))

local X, Y      = (undoH1 + 1)/2 * s, (undoH2 + 1)/2 * s
local OffY, OffX = math.ceil(ColorWheel.AbsoluteSize.X*X), math.ceil(ColorWheel.AbsoluteSize.Y*Y)
``````

Although this yielded no good results: https://gyazo.com/eda5868ec0876979a5cb415785cc057a

As you can see (output), OG Offset is equivalent to the mouse offset, H/S to mouse is my conversion of color back into position.

Just simplifying it a bit:

``````local angle = math.pi - h * 2 * math.pi
local r = ColorWheel.AbsoluteSize.X / 2
local x = r * math.cos(angle)
local y = r * math.sin(angle)
``````

Based on how you’re defining `h` I’m assuming that you’re storing `h` as a number from 0 to 1, where 0 is on the left edge and it increases clockwise?

I can’t quite pinpoint the increase/decrease of values on the colorwheel, although, this gif best describes the issue with your code: (referring to the simplification you sent above, please keep in mind the differences in the values)

Honestly, the O.G. values don’t look quite right to me in the first place. How are you printing them?

1 Like

I apologize for responding quite late but I figured out an alternative.

``````local Angle = math.pi - h * 2 * math.pi
local R = s (original value, refer to top line of code on page) * ColorWheel.AbsoluteSize.X / 2
local X = R * math.cos(Angle)
local Y = R * math.sin(Angle)
``````

then adding the origin pos of the color wheel yielded correct values

Oh sorry man, I meant to write that `s * `. Glad you figured it out 1 Like