/**
         * Makes a draw on the distribution.  The results are added to parameter 'x'
         */
        public void next(DMatrixRMaj x)
        {
            for (int i = 0; i < r.numRows; i++)
            {
                r.set(i, 0, (double)rand.NextGaussian());
            }

            CommonOps_DDRM.multAdd(A, r, x);
        }
Пример #2
0
        /**
         * <p>
         * Sets each element in the matrix to a value drawn from an Gaussian distribution with the specified mean and
         * standard deviation
         * </p>
         *
         * @param mat The matrix who is to be randomized. Modified.
         * @param mean Mean value in the distribution
         * @param stdev Standard deviation in the distribution
         * @param randJava.Util.Random number generator used to fill the matrix.
         */
        public static void fillGaussian(DMatrixD1 mat, double mean, double stdev, Java.Util.Random rand)
        {
            double[] d    = mat.getData();
            int      size = mat.NumElements;

            Java.Util.Random random2 = new Java.Util.Random();
            for (int i = 0; i < size; i++)
            {
                d[i] = mean + stdev * (double)random2.NextGaussian();
            }
        }
Пример #3
0
            /**
             * Splatter paint in an area.
             *
             * Chooses random vectors describing the flow of paint from a round nozzle
             * across a range of a few degrees.  Then adds this vector to the direction
             * indicated by the orientation and tilt of the tool and throws paint at
             * the canvas along that vector.
             *
             * Repeats the process until a masterpiece is born.
             */
            private void DrawSplat(Canvas canvas, float x, float y, float orientation,
                                   float distance, float tilt, Paint paint)
            {
                float z = distance * 2 + 10;

                // Calculate the center of the spray.
                float nx = (float)(Math.Sin(orientation) * Math.Sin(tilt));
                float ny = (float)(-Math.Cos(orientation) * Math.Sin(tilt));
                float nz = (float)Math.Cos(tilt);

                if (nz < 0.05)
                {
                    return;
                }
                float cd = z / nz;
                float cx = nx * cd;
                float cy = ny * cd;

                for (int i = 0; i < SPLAT_VECTORS; i++)
                {
                    // Make a random 2D vector that describes the direction of a speck of paint
                    // ejected by the nozzle in the nozzle's plane, assuming the tool is
                    // perpendicular to the surface.
                    double direction  = mRandom.NextDouble() * Math.PI * 2;
                    double dispersion = mRandom.NextGaussian() * 0.2;
                    double vx         = Math.Cos(direction) * dispersion;
                    double vy         = Math.Sin(direction) * dispersion;
                    double vz         = 1;

                    // Apply the nozzle tilt angle.
                    double temp = vy;
                    vy = temp * Math.Cos(tilt) - vz * Math.Sin(tilt);
                    vz = temp * Math.Sin(tilt) + vz * Math.Cos(tilt);

                    // Apply the nozzle orientation angle.
                    temp = vx;
                    vx   = temp * Math.Cos(orientation) - vy * Math.Sin(orientation);
                    vy   = temp * Math.Sin(orientation) + vy * Math.Cos(orientation);

                    // Determine where the paint will hit the surface.
                    if (vz < 0.05)
                    {
                        continue;
                    }
                    float pd = (float)(z / vz);
                    float px = (float)(vx * pd);
                    float py = (float)(vy * pd);

                    // Throw some paint at this location, relative to the center of the spray.
                    mCanvas.DrawCircle(x + px - cx, y + py - cy, 1.0f, paint);
                }
            }