/// <summary> /// get index for fluid cell under mouse position. /// </summary> /// <param name="p"></param> /// <returns></returns> private IntPoint ScreenToField(Point p) { IntPoint result = new IntPoint(); result.X = (int)(p.X / ActualWidth * N); result.Y = (int)(p.Y / ActualHeight * N); return result; }
private void UpdateDensity(IntPoint pt) { var i = pt.X; var j = pt.Y; dens_prev[i, j] = 10; }
private void UpdateVelocity(IntPoint pt) { var i = pt.X; var j = pt.Y; u_prev[i, j] = (x - xOld) * 5; v_prev[i, j] = (y - yOld) * 5; }
private IntPoint NormalizePoint(IntPoint pt) { if (pt.X > N) pt.X = N; else if (pt.X < 1) pt.X = 1; if (pt.Y > N) pt.Y = N; else if (pt.Y < 1) pt.Y = 1; return pt; }
protected void UpdateVelocity(IntPoint pt) { var i = pt.X; var j = pt.Y; solver.uOld[I(i, j)] = (x - xOld) * 5; solver.vOld[I(i, j)] = (y - yOld) * 5; }
protected IntPoint NormalizePoint(IntPoint pt) { if (pt.X > n) pt.X = n; else if (pt.X < 1) pt.X = 1; if (pt.Y > n) pt.Y = n; else if (pt.Y < 1) pt.Y = 1; return pt; }
protected void CreateObstacle(IntPoint pt) { solver.OccupiedCells[I(pt.X, pt.Y)] = true; }
protected void DeleteObstacle(IntPoint pt) { solver.OccupiedCells[I(pt.X, pt.Y)] = false; }
/// <summary> /// get index for fluid cell under mouse position. /// </summary> /// <param name="p"></param> /// <returns></returns> protected IntPoint ScreenToField(Point p) { IntPoint result = new IntPoint(); result.X = (int)(n - p.X / ActualWidth * n + 1); result.Y = (int)(p.Y / ActualHeight * n + 1); return result; }
protected void UpdateDensity(IntPoint pt) { var i = pt.X; var j = pt.Y; solver.densityOld[I(i, j)] = 100; }
private static bool GetCoordinate(DataSource dataSource, Point point, out IntPoint coordinate) { var ix = IndexOf(dataSource.XCoordinates, point.X); int iy = IndexOf(dataSource.YCoordinates, point.Y); coordinate = new IntPoint(ix, iy); return ix > -1 && iy > -1; }
private static Vector GetVector(DataSource dataSource, IntPoint coordinate, Point point) { int x = coordinate.X; int y = coordinate.Y; var x0 = dataSource.XCoordinates[x]; var x1 = dataSource.XCoordinates[x + 1]; var y0 = dataSource.YCoordinates[y]; var y1 = dataSource.YCoordinates[y + 1]; double xRatio = GetRatio(x0, x1, point.X); double yRatio = GetRatio(y0, y1, point.Y); Vector v00 = dataSource.Data[x, y]; Vector v01 = dataSource.Data[x, y + 1]; Vector v10 = dataSource.Data[x + 1, y]; Vector v11 = dataSource.Data[x + 1, y + 1]; Vector result = (1 - xRatio) * v00 + xRatio * v10 + (1 - xRatio) * v01 + xRatio * v11 + (1 - yRatio) * v00 + yRatio * v01 + (1 - yRatio) * v10 + yRatio * v11; result *= 0.25; return result; }
private static ConvolutionColor GetColor(DataSource dataSource, int[] pixels, IntPoint coordinate, Point point) { int x = coordinate.X; int y = coordinate.Y; var x0 = dataSource.XCoordinates[x]; var x1 = dataSource.XCoordinates[x + 1]; var y0 = dataSource.YCoordinates[y]; var y1 = dataSource.YCoordinates[y + 1]; double xRatio = GetRatio(x0, x1, point.X); double yRatio = GetRatio(y0, y1, point.Y); int width = dataSource.Width; var v00 = pixels[x + y * width]; var v01 = pixels[x + 1 + y * width]; var v10 = pixels[x + (y + 1) * width]; var v11 = pixels[x + 1 + (y + 1) * width]; //var result = (int)(((1 - xRatio) * v00 + xRatio * v10 + // (1 - xRatio) * v01 + xRatio * v11 + // (1 - yRatio) * v00 + yRatio * v01 + // (1 - yRatio) * v10 + yRatio * v11) * 0.25); var result = v00; return ConvolutionColor.FromArgb(result); }
private static Vector GetVector(DataSource dataSource, IntPoint index, Point position) { int ix0 = index.X; int iy0 = index.Y; int ix1 = ix0 + 1 < dataSource.Width ? ix0 + 1 : ix0; int iy1 = iy0 + 1 < dataSource.Height ? iy0 + 1 : iy0; var x0 = dataSource.XCoordinates[ix0]; var x1 = dataSource.XCoordinates[ix1]; var y0 = dataSource.YCoordinates[iy0]; var y1 = dataSource.YCoordinates[iy1]; double xRatio = GetRatio(x0, x1, position.X); double yRatio = GetRatio(y0, y1, position.Y); Vector v00 = dataSource.Data[ix0, iy0]; Vector v01 = dataSource.Data[ix0, iy1]; Vector v10 = dataSource.Data[ix1, iy0]; Vector v11 = dataSource.Data[ix1, iy1]; Vector result = (1 - xRatio) * v00 + xRatio * v10 + (1 - xRatio) * v01 + xRatio * v11 + (1 - yRatio) * v00 + yRatio * v01 + (1 - yRatio) * v10 + yRatio * v11; result *= 0.25; return result; }
private static bool GetCoordinate(DataSource dataSource, Point point, out IntPoint coordinate) { int ix = BinarySearch.SearchInterval(dataSource.XCoordinates, point.X); int iy = BinarySearch.SearchInterval(dataSource.YCoordinates, point.Y); coordinate = new IntPoint(ix, iy); return ix > BinarySearch.NotFound && iy > BinarySearch.NotFound; }