Advertisement

Need an algoritm (again). Might be simple

Started by August 15, 2001 02:58 PM
2 comments, last by MindWipe 23 years, 6 months ago
I have a problem. I need an "effect" that would change a array: int a[10] that would look like
  
1   10  20  30  40  50  60  70  80  90
*   *   *   *   *   *   *   *   *   * 
  
to this:
  
1                          67(something like that) 
** *  *   *    *   *  * * **
  
if the distance between point one and the last point are shorter then original Look at the image here: (You might need to link to the image to see it) Okey... some of my ideas. You have the integers: 1-90 in 10 integer if the integers later are 1-50 I tought to do like this: old_a[9]-a[9]/10(size of array) X=90-50/10 okey.. now I know how much should be taken away from each. Then I tought of making an acceleration to get that I did like this: X2 = X*2/size of array now it would accelerate from 0 to X*2 I first tried just to make this work:
  
1                            50
*** *  *   *   *   *    *    *
  
And each time I went one forward in the array(while giving them values) X3+=X2*(Current array nr); And then I subtracted that X3 from what it normally would have been. But when X2 was over 1 it started to go wrong. Not sure what to do. And not sure if you understand my problem Anyway, got any ideas? /MindWipe "If it doesn't fit, force it; if it breaks, it needed replacement anyway." Edited by - MindWipe on August 15, 2001 4:03:51 PM
"To some its a six-pack, to me it's a support group."
Dunno if that helps, but, have you tried using the cos function to do that ?

  /// N values waving in the interval 0..Mvoid wave(int n,int m,int r[]){  float d=PI/n;  float angle=0;  for (int i=0;i<n;i++,angle+=d)  {    /// [0;N] -> [1;-1]    float val=cosf(angle);    /// [1;-1] -> [2;0]    val=val+1    /// [2;0] -> [0;2]    val=2-val;    /// [0;2] -> [0;1]    val=val/2;    /// [0;1] -> [0;M]    r[i]=(int)(val*m);  }}  


Y.
Advertisement
That''s a GREAT idea. Stupid of me of my not to have thought of it before.

Thanks! Gonna try that

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."
Hmm.... sounded good. Now I''m not sure how to implant it

/MindWipe

"If it doesn''t fit, force it; if it breaks, it needed replacement anyway."
"To some its a six-pack, to me it's a support group."

This topic is closed to new replies.

Advertisement