コード例 #1
0
ファイル: VectorField.cs プロジェクト: silky/calcflow
    /*
     * Samples a vector function on a certain domain
     * and stores the results
     */
    public void SampleVectorField(VectorFieldFunctions.VectorFieldFunction myFn, float x_min, float x_max, float y_min, float y_max, float z_min, float z_max, float delta)
    {
        currFn = sampleFunction;

        max_magnitude = 0f;

        for (float x_temp = x_min; x_temp <= x_max; x_temp += delta)
        {
            for (float y_temp = y_min; y_temp <= y_max; y_temp += delta)
            {
                for (float z_temp = z_min; z_temp <= z_max; z_temp += delta)
                {
                    Vector3 target    = new Vector3(x_temp, y_temp, z_temp);
                    Vector3 result    = myFn(target);
                    Vector3 direction = result.normalized;
                    float   length    = result.magnitude;
                    if (length > max_magnitude)
                    {
                        max_magnitude = length;
                    }
                    startPts.Add(target);
                    offsets.Add(direction * length);
                }
            }
        }
    }
コード例 #2
0
    public void SampleTorus(VectorFieldFunctions.VectorFieldFunction myFn, float radius_torus, float radius_cross)
    {
        currFunction = sampleFunction;
        currMapping  = mappingOption;

        for (int i = 0; i < 36; i++)
        {
            float theta    = (float)i / 18f * Mathf.PI;
            float x_center = Mathf.Cos(theta) * radius_torus;
            float z_center = Mathf.Sin(theta) * radius_torus;
            float y_center = 0f;
            for (int j = 0; j < 12; j++)
            {
                float   omega   = (float)j / 6f * Mathf.PI;
                float   y       = Mathf.Sin(omega) * radius_cross;
                float   x       = Mathf.Cos(theta) * (Mathf.Cos(omega) * radius_cross + radius_torus);
                float   z       = Mathf.Sin(theta) * (Mathf.Cos(omega) * radius_cross + radius_torus);
                Vector3 startPt = new Vector3(x, y, z);
                startPt = transform.TransformPoint(startPt);
                Vector3 result = myFn(startPt);
                Vector3 normal = transform.InverseTransformPoint(startPt) - new Vector3(x_center, y_center, z_center);
                normal = normal.normalized;
                startPts.Add(startPt);
                results.Add(result);
                tangents.Add(Vector3.Cross(transform.TransformDirection(normal), result).normalized * 0.5f);
            }
        }

        /*
         * for(int i = 0; i < 36; i++)
         * {
         *  float u = (float)i / 18f * Mathf.PI;
         *  for(int j = 0; j < 36; j++)
         *  {
         *      float v = (float)i / 18f * Mathf.PI;
         *      float x = (radius_torus + radius_cross * Mathf.Cos(v)) * Mathf.Cos(u);
         *      float y = (radius_torus + radius_cross * Mathf.Cos(v)) * Mathf.Sin(u);
         *  }
         * }
         */
    }
コード例 #3
0
    public void SampleSphere(VectorFieldFunctions.VectorFieldFunction myFn, float radius)
    {
        currFunction = sampleFunction;
        currMapping  = mappingOption;

        float   y    = -radius + 0.5f;
        Vector3 temp = new Vector3(0, -radius, 0);

        temp = transform.TransformPoint(temp);
        startPts.Add(temp);
        results.Add(myFn(temp));
        tangents.Add(Vector3.Cross(temp, myFn(temp)).normalized * 0.5f);

        temp = new Vector3(0, radius, 0);
        temp = transform.TransformPoint(temp);
        startPts.Add(temp);
        results.Add(myFn(temp));
        tangents.Add(Vector3.Cross(temp, myFn(temp)).normalized * 0.5f);

        for (float currY = y; currY < radius; currY += 0.5f)
        {
            for (int i = 0; i < 36; i++)
            {
                float   theta   = (float)i / 18f * Mathf.PI;
                float   currR   = Mathf.Sqrt(radius * radius - currY * currY);
                float   currX   = currR * Mathf.Cos(theta);
                float   currZ   = currR * Mathf.Sin(theta);
                Vector3 startPt = new Vector3(currX, currY, currZ);
                Vector3 normal  = transform.TransformDirection(startPt.normalized);
                startPt = transform.TransformPoint(startPt);
                startPts.Add(startPt);
                Vector3 result = myFn(startPt);
                results.Add(result);
                tangents.Add(Vector3.Cross(normal.normalized, result.normalized).normalized * 0.5f);
            }
        }
    }