POV-Ray : Newsgroups : povray.newusers : How to: Sphere with 3D Electric Field Lines : Re: How to: Sphere with 3D Electric Field Lines Server Time
27 Apr 2024 16:36:29 EDT (-0400)
  Re: How to: Sphere with 3D Electric Field Lines  
From: William F Pokorny
Date: 27 Sep 2014 07:14:56
Message: <54269c30$1@news.povray.org>
On 09/26/2014 03:42 PM, Johann wrote:
> Good Evening everyone,
>
> I am new to the Group and to POV RAY generally and my interest is related of
> using POV RAY to model electrostatic fields.
> Could someone provide me a sample POV RAY code where it will demonstrate a
> sphere with its 3D Electrostatic Field (using the formula E=K*q/r^2) with field
> lines and another with contours? Then how can I modify the sample for two
> spheres with their fields interacting.
>
> I searched all over the Internet where one may find amazing POV RAY examples but
> none that could demonstrate 3D Electrostatic Fields (free code example) of a
> sphere or two of them in close proximity.
>
> I will really appreciate any help of yours.
>
> Have a great weekend!
>
> Kind Regards
>
> Johann
>
Hi Johann,

I don't have a simple method for the field lines, but perhaps the 
following code makes for a start on the contours. Field lines would 
intersect in a fashion perpendicular to the contours so I can sort of 
see complicated methods to come up with them, but nothing which fits in 
the time I can spend at the moment.

Bill P.

//
// Using isosurfaces to get equal potential contours
//
// This technique is slow even playing tricks below.
//
// Suggest to start :
//    povray +Ie_static.pov +A +D +THfs +H300 +W300
//
#version 3.7;
global_settings {
     assumed_gamma 1
     ambient_light srgb <1,1,1>
}
#declare Grey50 = srgbft <0.5,0.5,0.5,0,0>;
background {
     color Grey50
}
#declare Camera00 = camera {
     perspective
     location <5,5,-5.001>
     sky <0,1,0>
     angle 35
     right x*(image_width/image_height)
     look_at <0,0,0>
}
#declare White = srgbft <1,1,1,0,0>;
#declare Light00 = light_source {
     <50,150,-250>, White
}
#declare Red = srgbft <1,0,0,0,0>;
#declare CylinderX = cylinder {
     <-1,0,0>, <1,0,0>, 0.01
     pigment { color Red }
}
#declare Green = srgbft <0,1,0,0,0>;
#declare CylinderY = cylinder {
     <0,-1,0>, <0,1,0>, 0.01
     pigment { color Green }
}
#declare Blue = srgbft <0,0,1,0,0>;
#declare CylinderZ = cylinder {
     <0,0,-1>, <0,0,1>, 0.01
     pigment { color Blue }
}
#include "functions.inc"
#declare Fn00 = function (x,y,z,k,q) {
     (k*q)/(x*x+y*y+z*z+1e-7)
}
#declare Fn01 = function (x,y,z,_X,_Y,_Z,k,q) {
     Fn00(x-_X,y-_Y,z-_Z,k,q)           // Positions spheres
}
#declare Fn02 = function (x,y,z) {
     Fn01(x,y,z,2.5,0.0,0.0,1.0,-1.0)   // First sphere
}
#declare Fn03 = function (x,y,z) {
     Fn01(x,y,z,-2.5,0.0,0.0,1.0,1.0)   // Second sphere
}
#declare Fn04 = function (x,y,z) {
     Fn02(x,y,z)+Fn03(x,y,z)
}
#declare Magenta = srgbft <1,0,1,0,0>;

#macro EquPotential(_E)
difference {
    isosurface {
        function { Fn04(x,y,z*10) } // Scaling in z to get faster iso
        contained_by { box { <-9.5,-4.5,-0.45>,<4.5,4.5,0.45> } }
        threshold _E+0.005
        accuracy 0.0005
        max_gradient 5.5
        all_intersections
    }
    isosurface {
        function { Fn04(x,y,z*10) }
        contained_by { box { <-9.5,-4.5,-0.45>,<4.5,4.5,0.45> } }
        threshold _E
        accuracy 0.0005
        max_gradient 5.5
        all_intersections
    }
}
#end

// Could be a macro passed max and min
// potentials of all spheres in render.
#declare EquPotentialShells = union {
     EquPotential(-1.0/1)
     EquPotential(-1.0/2)  // list contours to plot
     EquPotential(-1.0/4)  // more = slower render
     EquPotential(-1.0/8)
     EquPotential(-1.0/16)
     EquPotential(0.0)
     EquPotential(1.0/16)
     EquPotential(1.0/8)
     EquPotential(1.0/4)
     EquPotential(1.0/2)
     EquPotential(1.0/1)
}
#declare Box00 = box {
     <-20,-9,-0.02>,<5,5,0.02>
}
#declare EquPotentialLines = intersection {
     object { Box00 }
     object { EquPotentialShells }
     pigment { color Magenta }
}

//---
camera { Camera00 }
light_source { Light00 }
object { CylinderX }
object { CylinderY }
object { CylinderZ }
object { EquPotentialLines }


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.