-2

I need to set an alpha value, which is derived of a float value.

I list the pairs of float:alpha below, and I hope you guys can give me a simple correlation:

Float:Alpha
0:0
6:0.5
12:1
18:0.5
24:0

The maximum float value is 24, alpha can't be more than 1. Inbetween values should be something parabolic/sine-like, with high resolution.

I suspect that this all involves a modulo. Please help me!

It would be helpful if you could express the formula in Objective-C syntax.

Thanks

Edit: to make myself clear: The left column is the input value, the right column is the output value.

Paraphrasing David:

"Hi, here is my input: 0, 6, 12, 18,24 and here is my output: 0, 0.5, 1, 0.5, 0. I need to generalize a solution. Halp."

4

2 回答 2

1

If you want a sine-wave the formula you're looking for is:

-(cos(n * pi / 12) - 1) / 2

Where n is the value from 0 to 24.

于 2013-02-26T00:31:36.553 回答
0

The formula I would use is:

CGFloat alpha = sin(radius / 24.0 * M_PI);

This gives 0 for 0 and 24, 1 for 12, and a proper sine wave for values in between.

Please note that 0.5 for 6 and 18 are not valid values for a proper sine wave. 0.707 is proper for a sine wave for 6 and 18.

于 2013-02-26T00:47:17.170 回答