We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Quadratic Values in Real-Time
Page Index Toggle Pages: 1
Quadratic Values in Real-Time (Read 644 times)
Quadratic Values in Real-Time
Dec 24th, 2008, 5:44am
 
Hello All,

Have tried searching and designing function(s) to store increments in quadratic fashion.Essentially, I am looking to have the use of a envelope that I can apply to anything in a real-time drawing process.

Here's a semi-random picture that visually shows what I am looking for;

http://www.filmsound.org/articles/ninecomponents/sound_envelope.gif

So, in this example the x-axis would be some form of time, perhaps derived from frameRate, and the y-axis say a color value.

Any links to known solutions or pointers on how to do this, for a non-math and non-programming whiz, are greatly appreciated!!

Re: Quadratic Values in Real-Time
Reply #1 - Dec 24th, 2008, 7:00am
 
Just in case no one answers:  quadratic as in polynomial function? or something more general?

I've noticed a remotely similar problem being discussed recently, but more general:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1137896034

I was definitely interested in this topic from "camera on rail" problem, but this may be applied to your case as well.

If it is specifically for a series of quadratic functions, it'll be relatively easy to create a class that describes the increments along a quadratic curve without above abstractions - it'll only need coefficients and range, and store them in an array.

I should at least ask this before I code away....oh, what the heck, I'll just write a stub:

Code:


ArrayList quadSegments = new ArrayList();

//...


class QuadSegment{
 float coeffA, coeffB, coeffC, range1, range2;
 QuadSegment(float coeffA, float coeffB, float coeffC, float range1, float range2){
   this.coeffA = coeffA;
   this.coeffB = coeffB;
   this.coeffC = coeffC;
   this.range1 = range1;
   this.range2 = range2;
 }
 boolean withinRange(){
   // TODO: stub
 }

 float getY(float x){
   // TODO: stub
 }
}


By the way, does anyone know how to do list comprehension in Java, for, say, withinRange()?

======edit======
ack, fixed a minor bug.  And followed PhiLho's advice and fixed my abuse of class for primitive values (have lots to learn about Java).
Re: Quadratic Values in Real-Time
Reply #2 - Dec 24th, 2008, 9:47am
 
I fail to understand the usage of quadratic here too (can also apply to complexity of algorithms!).

About your stub: you should avoid usage of classes for primitive values, unless really needed... Smiley
And I am not sure what you mean by "list comprehension".
Re: Quadratic Values in Real-Time
Reply #3 - Dec 24th, 2008, 4:03pm
 
Thanks for a good advice.  I guess I tend to abuse features Smiley  Fixed the stub.

As for list comprehension, I guess what I want is something like:

Code:

Float y = null
#here
for quadSegment in quadSegments where quadSegment.inRange(x)
y = quadSegment.getY(x)
end for

if y != null then
plot(x,y)
end if



But anyway, I guess I should have waited until OP clarifies the meaning of the quadratics.

Re: Quadratic Values in Real-Time
Reply #4 - Dec 24th, 2008, 4:56pm
 
I am not entirely sure the quadratic equation is needed...
Basically I want to use values from an xy graph on the fly.  I can think of a way to do it badly where I essentially make lots of lines to fake the curves often seen in graphs, but it would be more ideal to create the software the right way.

It appears that curvePoints as described in the link posted by sw01 is close to what I want, but the way it is used is self-defeating as each point has to be known to be found.  Thanks for the code stubs, but I don't see how they solve the problem...

Perhaps, I am making a simple problem complicated, but what the function should do is be passed parameters like an sound envelope; an attack, a sustain, and a decay.  This would allow for non-linear increment changes of color values.  Instead of increasing the color by fixed increments, it would increment dynamically based on what values are passed.

For example, if I used envelope(0.0, 0.7, 0.9, 1.0, whiteColorValue), where whiteColorValue is pure white, it would change towards white very quickly, but then as the whiteColorValue's max was approached the color would slowly change.
Re: Quadratic Values in Real-Time
Reply #5 - Dec 24th, 2008, 6:06pm
 
Ok, it's a little less vague now.  How about:

Code:

Class Envelope{
 float a,b,c,d,peak;
 ArrayList curveSegments;
 Envelope(float a, float b, float c, float d, float peak){
   this.a = a;
   this.b = b;
   this.c = c;
   this.d = d;
   this.peak = peak;
   curveSegments.add(new CurveSegment(a,b, 0.0, 1.0));
   curveSegments.add(new CurveSegment(b,c, 1.0, 8.0));
   curveSegments.add(new CurveSegment(c,d, 8.0, 0.0));
   
 }
 float getDependent(){
   int independent = frameCount();
   float answer = 0.0;
   /*
    * determine ATTACK SUSTAIN or DECAY
    * based on a, b, c, d
    */
    for(int i = 0; i < curveSegments.size(); i++){
      if(curveSegments.inRange(independent)){
        answer = curveSegments.getY(independent);
      }
    }
    return answer;
 }
}



And just write the CurveSegment class, which is not that different from QuadSegment class.

As far as entering the curve itself, you probably need to have a more stringent specification of where you derive it.  I'm kind of wondering if you want to simply trace a graph, or use some type of edge-detection from a drawn line.  Either way, it'll be a bit more complicated.
Page Index Toggle Pages: 1