0

now i am new to processing environment (using java) but i have much experience in java, other day I needed to sketch up some mathematical functions/parametric equations, now before you say...MATLAB is for that only...I must let you know that i know only java.

So basically the main part is the absolute value of sine function that i needed to draw, i was able to do it, but all i had trouble with was that i wanted to limit my sine curve to some constraints, Since i am using parameteric equation for this, i have a variable float t as my parameter. one way i can find is to get co-ordinates of start and end of curve and limit/condition my loop to only print in those limit of x. Other novice way was to set values of my parameter accordingly.

Later worked like charm however 1st one didnt, maybe i am loosing some concept or skipping something, if u would please help me :) , code goes as follows:

  float t=-80;






  void setup()
  {
   background(20);
   size(500,500);


   stroke(255);
    strokeWeight(5);

    println(" "+X+" "+Y);

    translate(width/2,height/2);


    for(;t<=80;){

    if(x(t)>218 && x(t)<281)

    {
    point(x(t), y(t));
    }
    t++;

    }
    }

     void draw() {println (mouseX +"," + mouseY);}``



      float x( float t)
     {
     return t;
     }
     float y(float t)
    {
     return abs(30*sin(t/10));
    }

please help also i have schematics of what i want to actually sayenter image description here

Ray S. Kan
  • 119
  • 2
  • 8
  • Your sketch doesn't work – user41805 Jan 17 '17 at 14:21
  • It's tested bro....It surely works – Ray S. Kan Jan 17 '17 at 17:04
  • It doesn't because `if(x(t)>218 && x(t)<281)` doesn't get triggered since `t` is always less than `80` as a result of the for-loop. – user41805 Jan 17 '17 at 17:07
  • Also you can remove your `x()` function. There really isn't any difference between using a value as it is than using a function. For examples, `x(t) == t`, so to clean up your code, you can remove `x()` – user41805 Jan 17 '17 at 17:11
  • True thing @Kritixi, that value of t never gets to 218/281 but the thing is that point(x,y) plots points on respective x,y co-ordinates of the canvas, if u remove the if condition u will see graph plotted, why? The value of t never got to 218, still it got plotted. That's what I am asking.....is it something with concept of point() function? Also, agreed that x(t) makes no sense, as it returns t only . – Ray S. Kan Jan 18 '17 at 03:52
  • You should learn to indent your code correctly. It will be much easier to understand and to see mistakes. – rghome Jan 19 '17 at 16:42

0 Answers0