winsrp 277 Report post Posted July 29, 2012 (edited) So I wanted to make a formula that would give me a the gradient point from 0 = nothing / full black to 1 = full / full white but, in a sphere so I cannot really print it to a bitmap. So for a cube that has 2 by 2 by 2 I came with the following formula (values go from -1 to 1 on all axes.). My math is really ugly. gradient = math.sin(1 - (math.abs(x) / radius)) * math.sin(1 - (math.abs(y) / radius)) * math.sin(1 - (math.abs(z) / radius)) as a plus I would like to be able to move the gradient center up or down in the y axis, but have no idea how. help is greatly appreciated, as my formula gives... funky results to say the best. Tx. Edited July 29, 2012 by winsrp 0 Share this post Link to post Share on other sites
winsrp 277 Report post Posted July 29, 2012 ok using some math and some brain, it comes down to this formula to produce a sphere... and it works as a gradient, but... radius has to be equal on all 3 sides... but I need one that can behave with different radius's on all axes. Math.Sqrt(radius ^ 2 - (x ^ 2 + y ^ 2 + z ^ 2)) Also still with the doubt on how to move the center and keep the gradient. 0 Share this post Link to post Share on other sites
winsrp 277 Report post Posted July 29, 2012 wow... math is surely killing me.. got the ellipse function after LOTS of excel testing. math.sqrt ( r1^2 - r1^2 * y^2 / r2^2 - r1^2 * z^2 / r3^2 - x^2) now I just need how to move the center point while maintaining the size of the gradient.. on the -1 to 1 range for all axes. 0 Share this post Link to post Share on other sites
hstubbs3 172 Report post Posted July 29, 2012 for the 2nd part of the question - move the center point without affecting the gradient itself... Just move the center point... example - your new 'center' is (0, .5 , 0) .. so subtract .5 from Y and look up the value there.. Generalized, a function f of vertex P [ f(p) ]can be solved at a new 'center' c using f(p - c) .. Written out longform this means substituting ( pX - cX ) everywhere you were using just X before, same with Y and Z. As for the 1st part.. should just be sqrt(x^2 + y^2 + z^2 ) - the gradients would change according to sphere radius.. like layers of an onion.. So ( 0,0,0 ) is black core.. ( 0, 1, 0 ) is white point ( "north pole" ) 0 Share this post Link to post Share on other sites