I am currently using same algorithm with the one on your link already and it is still too slow for android devices
From my link in the comments above:
Given
r = Sqrt((x - 0.5)^2 + (y - 0.5)^2)
a = ArcTan2(y - 0.5, x - 0.5)
n = Bulge factor (default = 1)
Set
x' = r^n * Cos(a) + 0.5
y' = r^n * Sin(a) + 0.5
(Remember that, in this equation, x
and y
span from 0 to 1. If your dimensions span from 0 to w
, replace 0.5
with w/2
)
Using a bit of math, we can see that
Cos(a) = Cos(ArcTan2(y - 0.5, x - 0.5))
= (x - 0.5)/r
Sin(a) = Sin(ArcTan2(y - 0.5, x - 0.5))
= (y - 0.5)/r
This makes the final resulting equation
r = (x - 0.5)^2 + (y - 0.5)^2
n = Bulge factor (default = 0)
Set
x' = r^n * (x - 0.5) + 0.5
y' = r^n * (y - 0.5) + 0.5
(I removed the square-root since we take the result to a real-power anyways... so really to make this equivalent we should use n/2
instead of n
, but since we are defining "bulge-factor," we can just leave out the extra division)
With only a handful of multiplications and a single real-exponentiation, this is probably the fastest you can hope to get.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…