Trapezoidal Waves

If images are not shown try to refresh the page. If you like this website, please disable any AdBlock software!

You are currently reading a thread in /sci/ - Science & Math

You are currently reading a thread in /sci/ - Science & Math

Thread images: 4

Anonymous

Trapezoidal Waves 2015-12-31 23:04:08 Post No. 7754984

[Report] Image search: [iqdb] [SauceNao] [Google]

Trapezoidal Waves 2015-12-31 23:04:08 Post No. 7754984

[Report] Image search: [iqdb] [SauceNao] [Google]

Hey /sci/,

I'm trying to program a function that simply takes an integer, but cycles through all non-grey RGB values (i.e. one value is 255, one value is 0, one changes). My current method requires a lot of if-statements, so I was wondering if there was a mathematical approach I could take. The value of each color's brightness has a trapezoidal waveform, and so far I have this function (couldn't get latex to work for some reason so bare with me):

(255/pi) * [ sin^-1( sin( pi/2 * x ) ) + cos^-1( cos( pi/2*x ) ) ]

However I want to "stretch" just the horizontal parts so they last for a longer interval (picture is a visual explanation), so that the values read as follows:

x=0, y=0

1 <= x <= 3. y=255

4 <= x <= 6, y=0

Any ideas how to achieve this mathematically, without resorting to piece-wise?

>>

>>7754984

Op here

To clarify, I want to preserve the characteristic that the wave goes from 0 to 255 in an interval of 1, or [x,x+1], so normal sinusoidal stretching won't suffice.

>>

File: 1923678_992917327431588_5606972995644480623_n.jpg (41 KB, 640x640)
Image search:
[iqdb]
[SauceNao]
[Google]

41 KB, 640x640

>>

>>7754984

Pre-generate a lookup table

>>

>>7754984

Let R3 represent an RGB space.

Imagine an object flying around in an orbit.

The position of that object marks your RGB value.

>>

Why not something like

min( 255, K - L * | 255 * (x-offset) | )

where you adjust the offset, K and L to your liking? Deep down, using min and abs is obviously the same as nested if-statements, but that'd still yield a simple formula.

>>

>>7756650

yes, here is an extended version

https://www.desmos.com/calculator/cndmbbi3qa

(One uses mod and the other arcsin(sin(x)), I dont know which one is more efficient)

>>

>>

>>7754984

Just use the HSV color space and convert back to RGB.

>>

>>7754984

Matlab can realise yo dreams homie!!

>>

What's the point of using asin(sin(x)), asin is just inverse of sin, so wouldn't it just return it's argument?

>>

>>7759666

Depends on which interval you work. asin always returns values between -pi/2 and pi/2 and pi/2*x obviously doesn't. In the interval -1 to 1, it's the same. But outside that, pi/2*x is a straight line and asin(sin(pi/2*x)) is a triangle.

Thread images: 4

Thread DB ID: 377580

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.

This is a 4chan archive - all of the shown content originated from that site. This means that 4Archive shows their content, archived. If you need information for a Poster - contact them.

If a post contains personal/copyrighted/illegal content, then use the post's