Need help creating a sweep line for radar simulation

edited June 2015 in How To...

Back again! This is for that project I mentioned earlier - creating a radar simulation on the battleship New Jersey museum ship. I'm moving along with Processing - now have a nice radar "screen" and a line sweeping round 360 degrees continuously.

I'd like to make the sweep-line have a trailing edge of random noise to simulate the return pattern a radar screen displays.

One idea I have is to create a thin triangle (vertex at center of radar screen) where the height is the sweep of the radar, and the hypotenuse line would be a thick line of varying transparency and random shaped edge. The fill of the triangle might be some noise pattern and blend into the hypotenuse side...

Just not strong enough with Processing yet to figger this one out - so a little guidance on how to code such a triangle would be a great help.

Answers

  • how are you drawing your sweep line? radius * cos and sin?

    well, the one long edge of the triangle will be the exact same line and the other long edge will be a few degrees behind it.

    use beginShape(TRIANGLES) and three calls to vertex(x, y). get that working and then add a texture using the vertex(x, y, u, v) version.

  • As koogs mentioned, you can position the triangle as three points, I'll call them A, B, and C:

    • A is positioned at the center

    • B is positioned using cos(theta) and sin(theta) where theta is some angle (in radians)

    • C is also positioned using trigonometry but behind B in terms of Polar Coordinates by subtracting some number from theta


    Below is a simple sketch that places a triangle that is just filled in solidly. It will take some creativity to implement the noise effect you mentioned, maybe you could make an image (in Photoshop or something) to describe it?

    PVector a, b, c;
    float theta, radius;
    
    void setup() {
      size(400, 400);
      fill(0, 255, 0);
      noStroke();
    
      // Center point, never changes might as well assign it here
      a = new PVector(width/2, height/2);
    
      // Distance from the center to the other two triangle points
      radius = min(width, height)/2;
    
      // Maintains rotation state (in radians)
      theta = 0.0;
    }
    
    void draw() {
      background(0);
    
      // Position point c slightly behind point b (Polar Coordinates)
      float cOffset = PI*0.125;
      b = new PVector(a.x+cos(theta)*radius, a.y+sin(theta)*radius);
      c = new PVector(a.x+cos(theta-cOffset)*radius, a.y+sin(theta-cOffset)*radius);
    
      triangle(a.x, a.y, b.x, b.y, c.x, c.y);
    
      // Adding an arbitrary number to the current rotation state
      theta += 0.01;
    }
    
  • Answer ✓

    Just as an option, maybe it is easier to create a trail of your moving line? You'll need to make an array and draw a couple of lines that would decrease their opacity in time. I could only find the examples with ellipses, however the principle is the same and you'll not need to mess with pixels. http://www.openprocessing.org/sketch/48961

  • edited June 2015 Answer ✓

    Something like this, sorry for formatting.

    int cx; 
    int cy; 
    int r = 200;
    int x = new int[100];
    int y = new int[100];
    
    void setup() {
      size(600, 600);
      cx = width/2;
      cy = height/2;
    }
    void draw() {
      background (0);
      stroke(0,200,0); 
      float t = millis()/1500; 
      for(int i = 0; i < 100; i++){
         x[i] =(int) (cx+r*cos(t - i*0.01)); 
         y[i] =(int) (cy+r*sin(t - i*0.01));
         stroke(0, 200 - i * 2, 0); 
         line(cx, cy, x[i], y[i]);
      }
    }
    
  • Thanks to all for the helpful ideas. Currently I am rotating an arc and using pushMatrix and popMatrix to make changes. But your examples will def help me refine things. I was aware of Processing but only now took a look at it - what an awesome environment and tool!

Sign In or Register to comment.