# Finding the velocity at a specific point using the PixelFlow library

**URL:** <https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603>\
**Category:** Libraries\
**Created:** [November 18, 2019, 6:09am UTC](https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603 "2019-11-18T06:09:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BongoTurtle](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@BongoTurtle](https://discourse.processing.org/u/BongoTurtle)\
**Post date:** [November 18, 2019, 6:09am UTC](https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603/1 "2019-11-18T06:09:46Z")

</div>

How would I find the velocity at a specific point for the basic 2D flow like in the example:

```auto
// FLUID SIMULATION EXAMPLE
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
import com.thomasdiewald.pixelflow.java.fluid.DwFluid2D;

// fluid simulation
DwFluid2D fluid;

// render target
PGraphics2D pg_fluid;

public void setup() {
  size(800, 800, P2D);

  // library context
  DwPixelFlow context = new DwPixelFlow(this);

  // fluid simulation
  fluid = new DwFluid2D(context, width, height, 1);

  // some fluid parameters
  fluid.param.dissipation_velocity = 0.70f;
  fluid.param.dissipation_density = 0.99f;

  // adding data to the fluid simulation
  fluid.addCallback_FluiData(new DwFluid2D.FluidData() {
    public void update(DwFluid2D fluid) {
      if (mousePressed) {
        float px = mouseX;
        float py = height-mouseY;
        float vx = (mouseX - pmouseX) * +15;
        float vy = (mouseY - pmouseY) * -15;
        fluid.addVelocity(px, py, 14, vx, vy);
        fluid.addDensity (px, py, 20, 0.0f, 0.4f, 1.0f, 1.0f);
        fluid.addDensity (px, py, 8, 1.0f, 1.0f, 1.0f, 1.0f);
      }
    }
  });

  pg_fluid = (PGraphics2D) createGraphics(width, height, P2D);
}

public void draw() {    
  // update simulation
  fluid.update();

  // clear render target
  pg_fluid.beginDraw();
  pg_fluid.background(0);
  pg_fluid.endDraw();

  // render fluid stuff
  fluid.renderFluidTextures(pg_fluid, 0);

  // display
  image(pg_fluid, 0, 0);
}

```

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 19, 2019, 10:01pm UTC](https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603/2 "2019-11-19T22:01:12Z")

</div>

Hi @BongoTurtle,

Last time I had to retrieve the velocity using the PixelFlow library I used this [example code](https://github.com/diwi/PixelFlow/blob/master/examples/Fluid2D/Fluid_GetStarted_TexDataTransfer3/Fluid_GetStarted_TexDataTransfer3.java) as a reference.

I pretty much copy-pasted the snippet between line 90 and 128. The velocity sampling happens on line 118 and 119:

```auto
float vel_x = data_vel[gid_fluid * 2 + 0];
float vel_y = data_vel[gid_fluid * 2 + 1];

```

---

<div class="post-metadata">

**Author:** ![BongoTurtle](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@BongoTurtle](https://discourse.processing.org/u/BongoTurtle)\
**Post date:** [November 21, 2019, 12:23am UTC](https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603/3 "2019-11-21T00:23:45Z")

</div>

I’m not sure what all I need to copy in, and when I try to run the example code it doesn’t like the line at the top “package Fluid2D.Fluid\_GetStarted\_TexDataTransfer3;” or “public class Fluid\_GetStarted\_TexDataTransfer3 extends PApplet {”.

---

<div class="post-metadata">

**Author:** ![BongoTurtle](https://avatars.discourse-cdn.com/v4/letter/b/df788c/32.png) [@BongoTurtle](https://discourse.processing.org/u/BongoTurtle)\
**Post date:** [November 23, 2019, 6:58am UTC](https://discourse.processing.org/t/finding-the-velocity-at-a-specific-point-using-the-pixelflow-library/15603/4 "2019-11-23T06:58:39Z")

</div>

Ok I figured out how to get it working but it’s very slow even for a relatively small number of grid points. The way I need to use it only requires being able to test certain points but anywhere on a 1080p screen, so I’m wondering if it’s possible only to load the velocity at certain points without having to test all the others? It seems the only way to test the velocity is to test the entire screen at even intervals.
