Reputation: 11399
I have a math problem.
I am dealing with a graphics function that defines a gradient size. However this size is not in pixels but in a value ranging from 0 to 1.
I would like to find a formula to automatically determine the desired value for any size.
But just using my eyes I have discovered that
Does anybody know a formula to calculate the size of a the value for a given pixel size? Or does anybody with a good mathematical understanding see the underlying formula right away? The values are not perfectly right, I think. I had to use my eyes to determine which value is required to produce the gradient I need:
Upvotes: 0
Views: 79
Reputation: 14059
Try this formula. It's not completely accurate, but I hope it's accurate enough:
FocusScale = 1 - 37.251 / uSize
Upvotes: 1
Reputation: 11399
Private Function pGetFocusScale(ByVal uSize As Double) As Double
Dim d As Double
d = 20 / (uSize / 2)
Return 1 - d
End Function
It is used for
Dim nPathGradientBrush As New PathGradientBrush(somePath)
Dim dblFocusX As Double = pGetFocusScale(someRect.Width)
Dim dblFocusY As Double = pGetFocusScale(someRect.Height)
nPathGradientBrush.FocusScales = New System.Drawing.PointF(dblFocusX, dblFocusY)
Upvotes: 1