Public Group

This topic is 2245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

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 by winsrp

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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" )

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
14
5. 5

• 10
• 9
• 16
• 9
• 9
• ### Forum Statistics

• Total Topics
632594
• Total Posts
3007304

×