3 Dimensional Plot of Electrical or Gravitational Potential 
 
 
These diagrams can represent either electrical or gravitational potential in 3D (they appear the same).  There are many ways to represent diagrams in 3D.  The two shown here are isosurface plots and volume rendering.  An isosurface plot is the 3D equivalent of a 2D contour plot.  3D volume rendering is analogous to the 2D color maps on the main page, where each point in space is associated with a color.  A cut can be taken out to show the inside of the 3D object.  These diagrams were produced by the program T3D.  The data used for this diagram was produced by program jam1 which is written in Fortran 90.  These images were reduced; in full size they are more clear. 
Equation Visualized: 
  • Electric Potential: V(x,y,z) = (k*qc)/r
  • Gravitational Potential: V(x,y,z) = -(G*Mc)/r
"r" = sqrt[(x-xc)2+(y-yc)2+(z-zc)2] is the distance between the center and a test particle, "xc", "yc", and "zc" are the coordinates of the center, "x", "y", and "z" are the coordinates of the test particle, "V" is the potential, "k" is Coulomb's constant, "qc" is the charge at the center, "G" is the universal gravitational constant, "Mc" is the mass at the center 
 
 
 
 
These isosurface plots consist of three parts: an inner opaque sphere, which is the potential of a 3D surface, an outer translucent sphere, which represents the potential of another 3D surface, and two perpendicual planes rotated to a certain angle.
 
This volume rendered diagram displays the same data in a different way.  A cut-out of the cube allows one to look inside.
 
 program jam1 
      use physics 
      implicit none  
      integer :: i, j, n 
      integer, parameter :: yd=50, xd=50, zd=50 
      real, parameter :: qe=1.602e-19 
      real ::  xi, yi, zi, q=1.0e10*qe  
      real :: dx=2, dy=2, dz=2 
      character*40 :: prompt = 'enter xi, yi, and zi' 
      real, dimension(xd) :: x 
      real, dimension(yd) :: y 
      real, dimension(zd) :: z 
      real, dimension(xd,yd,zd) :: v 
      print *, prompt 
      read (*,*) xi, yi, zi 
      do i=1,xd 
          x(i)=dx*i 
      end do 
      do j=1,yd 
          y(j)=dy*j 
      end do 
      do n=1,zd 
          z(n)=dz*n 
      end do 
      call potential(v, xi, yi, zi, x, y, z, q)  
      do n=1, zd 
         do j=1, yd 
            write (7,*) v(:,j,n) 
         end do 
      end do 
      end program jam1 



      module physics 
! this module contains physics subroutines 
      type vec2d 
         real :: x, y 
      end type vec2d 
      type vec3d 
         real :: x, y, z 
      end type vec3d 

! global constants for subroutines 
      real :: k=8.99E9, rad=1 

      interface potential 
         module procedure potential2D, potential3D 
      end interface 
      interface electricfield 
         module procedure electricfield2D, electricfield3D 
      end interface 
     interface add 
         module procedure addvec2d, addvec3d 
      end interface 
      contains 

      subroutine addvec2d(a, b) 
! this subroutine adds two 2d vectors 
! input: a,b 
! output: a 
      type (vec2d), dimension(:,:) :: a, b 
      a%x=a%x+b%x 
      a%y=a%y+b%y 
      end subroutine addvec2d 

      subroutine addvec3d(a, b) 
! this subroutine adds two 3d vectors 
! input: a,b 
! output: a 
      type (vec3d), dimension(:,:,:) :: a,b 
      a%x=a%x+b%x 
      a%y=a%y+b%y 
      a%z=a%z+b%z 
      end subroutine addvec3d 

      subroutine electricfield2D(e,point0,x,y,q) 
! this subroutine calculates 2D electric field of point charge 
! input variables are: point0,q,x,y 
! output variables are: e 
! point0%x and point0%y are locations of point charge 
! q is the charge in coulombs 
! x and y are locations in space where electric field is calculated 
! e%x and e%y are the components of the electric field 
      real :: v, r 
      real :: q 
      type (vec2d) :: point0 
      real, dimension(:) :: x, y 
      type (vec2d), dimension(:,:) :: e 
      do i=1, size(x) 
         do j=1, size(y) 
            r=sqrt((x(i)-point0%x)**2+(y(j)-point0%y)**2) 
            If (r<rad) r=rad 
            v=(k*q)/r**2 
            e(i,j)%x=v*(x(i)-point0%x)/r 
            e(i,j)%y=v*(y(j)-point0%y)/r 
        end do 
      end do 
      end subroutine electricfield2D 

      subroutine electricfield3D(e,point0,x,y,z,q) 
! this subroutine calculates 3D electric field of point charge 
! input variables are: point0,q,x,y,z 
! output variables are: e 
! Point0%x, point0%y, and point0%z are locations of point charge, 
! q is the charge in coulombs 
! x, y, and z are locations in space where electric field is calculated 
! e%x, e%y, and e%z are the components of the electric field 
      real :: v, r 
      real :: q 
      type (vec3d) ::  point0 
      real, dimension(:) :: x, y, z 
      type (vec3d), dimension(:,:,:) :: e 
      do n=1, size(z) 
         do j=1, size(y) 
            do i=1, size(x) 
               r=sqrt((x(i)-point0%x)**2+(y(j)-point0%y)**2+(z(n)-point0%z)**2) 
               If(r<rad) r=rad 
               v=(k*q)/r**2 
               e(i,j,n)%x=v*(x(i)-point0%x)/r 
               e(i,j,n)%y=v*(y(j)-point0%y)/r 
               e(i,j,n)%z=v*(z(n)-point0%z)/r 
             end do 
        end do 
      end do 
      end subroutine electricfield3D 

      subroutine potential2D(pot,point0,x,y,q) 
! this subroutine calculates 2D electrical potential of point charge 
! input variables are: point0,q,x,y 
! output variables are: pot 
! point0%x and point0%y are locations of point charge, 
! q is the charge in coulombs 
! x and y are locations in space where potential is calculated 
! pot is the electrical potential 
      real :: r 
      real :: q 
      type (vec2d) :: point0 
      real, dimension(:) :: x, y 
      real, dimension(:,:) :: pot 
      do i=1, size(x) 
         do j=1, size(y) 
            r=sqrt((x(i)-point0%x)**2+(y(j)-point0%y)**2) 
            If (r<rad) r=rad 
            pot(i,j)=(k*q)/r 
        end do 
      end do 
      end subroutine potential2D 

      subroutine potential3D(pot,point0,x,y,z,q) 
! this subroutine calculates 3D electrical potential of point charge 
! input variables are: point0,q,x,y,z 
! output variables are: pot 
! point0%x, point0%y, and point0%z are locations of point charge, 
! q is the charge in coulombs 
! x, y, and z are locations in space where potential is calculated 
! pot is the electrical potential 
      real :: r 
      real :: q 
      type (vec3d) :: point0 
      real, dimension(:) :: x, y, z 
      real, dimension(:,:,:) :: pot 
      do n=1, size(z) 
         do j=1, size(y) 
            do i=1, size(x) 
               r=sqrt((x(i)-point0%x)**2+(y(j)-point0%y)**2+(z(n)-point0%z)**2) 
               If (r<rad) r=rad 
               pot(i,j,n)=(k*q)/r 
            end do 
         end do 
      end do 
      end subroutine potential3D 
      end module physics 

Back to Main Page