Math Is Fun Forum
  Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ • π ƒ -¹ ² ³ °

You are not logged in.

#1 2005-11-03 13:37:23

ray
Member
Registered: 2005-11-03
Posts: 2

have a graph, looking for the function

Hi !

I am writing a 3D shader and I got this graph and I just can't figure out the function sad

function.jpg

The result value (given in greyscale values between 0=black and 1=white) depends on the two variables a and b.

It is for example,

0.5 when a=b
1 when a=1
0 when b=1
0.5+(a/2) when b=0
0.5+(b/2) when a=0

(is there a name for this kind of graph btw.?)

I think it must be a quite simple function.

Thanks in advanced for help smile
Ray

Offline

#2 2005-11-03 17:22:15

MathsIsFun
Administrator
Registered: 2005-01-21
Posts: 7,534

Re: have a graph, looking for the function

Calculate the slope (or angle) from any point to (1,1) and base it on that.

Example: (0.2,0.2) ==> Slope = (1-0.2)/(1-0.2) = 1 = 45°
Example: (0.9,0.2) ==> Slope = (1-0.2)/(1-0.9) = 8 = 83°

So you could say the first point was 45°/90° = 0.5, and the second 83°/90°  = 0.92

That should get you close.


"The physicists defer only to mathematicians, and the mathematicians defer only to God ..."  - Leon M. Lederman

Offline

#3 2005-11-04 01:48:50

ray
Member
Registered: 2005-11-03
Posts: 2

Re: have a graph, looking for the function

Thanks!

I have the solution now as:

if( (1-a) < (1-b) )

     r = 1 - ( (1-a) / (1-b) ) / 2;

else

     r = ( (1-b) / (1-a) ) / 2;

Ray

Offline

Board footer

Powered by FluxBB