public static void Main()
        {
            Vector integralSum = new Vector(0, 0, 0);
            double TAU = 2 * Math.PI;
            double PI = Math.PI;
            int    n = 1000;
            double R = 1.0;
            double theta, phi;

            double theta1 = 1 * PI / 180; //*
            double theta2 = PI;
            double phi1   = 0.0;
            double phi2   = TAU;

            double dtheta = (theta2 - theta1) / n;
            double dphi   = (phi2 - phi1) / n;

            Console.WriteLine(dtheta + " " + dphi);
            Console.WriteLine(dtheta * 180 / PI + " " + dphi * 180 / PI);

            for (double z = 0; z < 5.01; z += 0.01)
            {
                integralSum = new Vector(0, 0, 0);
                Vector testPoint = new Vector(0, 0, z);
                for (int i = 0; i < n; i++) //theta
                {
                    theta = theta1 + (i + 0.5) * dtheta;
                    for (int j = 0; j < n; j++) //phi
                    {
                        phi = phi1 + (j + 0.5) * dphi;

                        SphereVector currentVector = new SphereVector(R, theta, phi);
                        Vector       shellVector   = currentVector.toCartesian() - testPoint;
                        SphereVector toShell       = shellVector.toSpherical();
                        //currentVector.trace();
                        SphereVector currentField = new SphereVector(0, 0, 0);
                        currentField = Math.Sin(theta) * dtheta * dphi * Math.Pow(toShell.r, -2) * toShell.normalize();
                        //currentField.trace();
                        integralSum = integralSum + currentField.toCartesian();

                        /**
                         * SphereVector currentSphere = new SphereVector(R, theta, phi);
                         * Vector currentVector = currentSphere.toCartesian();
                         * Vector currentField = ????
                         **/

                        //integralSum.trace();
                    }
                }
                Console.WriteLine("Z = " + z);
                integralSum.trace();
            }
            //integralSum.trace();
            //Console.WriteLine(4 * PI);
        }
Beispiel #2
0
        public SphereVector toSpherical()
        {
            //When I fix this part, REMEMBER TO USE THE CORRECT COORDINATES!
            double r, theta, phi;

            theta = 0;
            phi   = 0;

            double PI = Math.PI;

            r = this.mag();
            if (this.zCoor > 0) //Has issues with certain octants and with negative z values
            {
                theta = Math.Acos((this.zCoor / r));
            }
            else if (this.zCoor < 0)
            {
                theta = Math.PI - Math.Acos((-this.zCoor / r));
            }
            else if (this.zCoor == 0)
            {
                theta = Math.PI / 2;
            }
            if (this.xCoor > 0)     //Quadrants I and IV
            {
                if (this.yCoor > 0) //Quadrant I
                {
                    phi = Math.Atan((this.yCoor / this.xCoor));
                }
                else if (this.yCoor < 0)   //Quadrant IV
                {
                    phi = 3 * PI * 0.5 + Math.Atan((this.xCoor / -this.yCoor));
                }
                else if (this.yCoor == 0)   //Positive x-axis
                {
                    phi = 0;
                }
            }
            else if (this.xCoor < 0) //Quadrants II and III
            {
                if (this.yCoor > 0)  //Quadrant II
                {
                    phi = PI * 0.5 + Math.Atan((-this.xCoor / this.yCoor));
                }
                else if (this.yCoor < 0)   //Quadrant III
                {
                    phi = PI + Math.Atan((this.yCoor / this.xCoor));
                }
                else if (this.yCoor == 0)   //Negative x-axis
                {
                    phi = PI;
                }
            }
            else if (this.xCoor == 0) //Y axis
            {
                if (this.yCoor > 0)   //Positive y-axis
                {
                    phi = PI / 2;
                }
                else if (this.yCoor < 0)   //Negative y-axis
                {
                    phi = 3 * PI / 2;
                }
                else if (this.yCoor == 0) //On the z-axis
                {
                    phi = 0;              //At this point it doesn't really matter
                }
            }
            SphereVector spherical = new SphereVector(r, theta, phi);

            return(spherical);
        }