Finding the Equation to Place RGB=255 128 0 on a Long Thin Shape

  • Context: High School 
  • Thread starter Thread starter Wes Turner
  • Start date Start date
  • Tags Tags
    Shape
Click For Summary

Discussion Overview

The discussion revolves around finding an equation to control the green (G) value in an RGB color gradient transitioning from red (RGB=255 0 0) to yellow (RGB=255 255 0) along a long thin shape. Participants explore various mathematical approaches to achieve a specific G value of 127.5 at a customizable position along the shape.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant proposes using a linear equation to adjust the G value, initially suggesting the equation y = 255x + 0 to place the G=127.5 at the midpoint of the shape.
  • Another participant warns that a quadratic equation may lead to negative values or exceed 255 depending on the chosen midpoint, suggesting alternatives like two linear relations or a spline.
  • A participant expresses uncertainty about the concept of two linear relations but acknowledges the potential of using a spline as a solution.
  • There is a suggestion to use an exponential distribution with an offset as a possible method for achieving the desired color gradient.
  • Further clarification is provided on the two linear relations, indicating a piecewise function where G(x) is defined differently on either side of the fixed point.

Areas of Agreement / Disagreement

Participants generally agree that a quadratic equation may not be suitable for this problem, but there is no consensus on the best approach, as multiple competing methods (linear relations, splines, exponential functions) are proposed and discussed.

Contextual Notes

Participants note potential limitations of the quadratic approach, including the risk of negative or excessively high values. The discussion does not resolve the best method to use, leaving the choice open to further exploration.

Wes Turner
Messages
68
Reaction score
15
I have a long thin shape (rope, bar). The color of the shape changes smoothly from red (RGB=255 0 0) at one end to yellow (RGB=255 255 0) at the other. I need an equation that will allow me to adjust the G value from 0 to 255 in a way that I can choose where on the shape it has the value 127.5 (equal parts red and yellow, RGB = 255 128 0), if the 127.5 is rounded.

The linear equation y = 255x + 0 places that point at the midpoint (0.5) of the shape. The rounded values at 0.1 intervals are:
Color shading.jpg


I would like an equation that will enable me to place the G=127.5 value anywhere on that shape from 0.0 to 1.0. I'm not sure if a quadratic equation is the best choice or some type of exponential. For the quadratic, I would have three points ((0.0), (k,127.5), (1,255)) and could solve 3 equations in 3 unknowns.

Is there a better way?

Thanks
 

Attachments

  • Color shading.jpg
    Color shading.jpg
    12.8 KB · Views: 589
Mathematics news on Phys.org
In general a quadratic equation will go to negative values if your midpoint is too close to the 255 side, and above 255 if it is tooclose to the right side. You could use two linear relations left and right of it, or use a spline.

An exponential distribution with an offset (##a+e^{bx+c}##) would work as well.
 
  • Like
Likes   Reactions: Wes Turner
mfb said:
In general a quadratic equation will go to negative values if your midpoint is too close to the 255 side, and above 255 if it is too close to the right side.
Yeah, after some testing, I discovered that the quadratic is not a good choice.

You could use two linear relations left and right of it, or use a spline.
I'm not sure what you mean by two linear relations, but a spline might be a good choice. I didn't think of that. Thanks.

An exponential distribution with an offset (##a+e^{bx+c}##) would work as well.
Another good suggestion. Thanks.
 
Wes Turner said:
I'm not sure what you mean by two linear relations
G(x)=c*x up to the fixed point in the middle, and G(x)=a+b*x from there to the end (where a+b=255 to satisfy G(1)=255).
 
  • Like
Likes   Reactions: Wes Turner
mfb said:
G(x)=c*x up to the fixed point in the middle, and G(x)=a+b*x from there to the end (where a+b=255 to satisfy G(1)=255).
Got it, thanks.
 

Similar threads

  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
30
Views
3K
Replies
16
Views
13K
Replies
6
Views
2K
  • · Replies 41 ·
2
Replies
41
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 14 ·
Replies
14
Views
3K
Replies
3
Views
5K
Replies
3
Views
3K