I am working on parsing data from file generated by a program, it can apply a shadow to text. In the UI you simply set an angle, length, and radius
With those values shown in the screenshot, that data is saved like this inside of an XML node
10|{1.41421356237309, -1.4142135623731}
The format is:
radius|{offsetX, offsetY}
I'd like to calculate these values back into the angle and length so I can return them in my parser. Looking around online I have only found the opposite: a way to calculate those offsets from the angle and length.
let length = 2;
let angle = 135;
let shadowX = Math.sin(angle * (Math.PI / 180)) * length;
let shadowY = Math.cos(angle * (Math.PI / 180)) * length;
console.log(shadowX, shadowY); //1.4142135623730951 -1.414213562373095
This is where I wish I'd paid more attention in my algebra classes. I have no idea how to proceed here to calculate the values I want. I need to be able to input those X/Y offset values and get the angle and length returned.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/RrV3C7Q
Comments
Post a Comment