POV-Ray : Newsgroups : povray.newusers : How to: Sphere with 3D Electric Field Lines : Re: How to: Sphere with 3D Electric Field Lines Server Time
11 May 2024 10:19:10 EDT (-0400)
  Re: How to: Sphere with 3D Electric Field Lines  
From: William F Pokorny
Date: 2 Oct 2014 22:49:52
Message: <542e0ed0$1@news.povray.org>
On 09/28/2014 04:11 PM, Johann wrote:
>
> Thank you Bill  very much! This is really very close to what I am trying to
> achieve. May I ask something:
> If I modify only the following declare expression:
> #declare Fn00 = function (x,y,z,k,q) {
> (k*q)/(x*x+y*y+z*z+1e-7)
> }
> would be enough to see a different rendered image or it is required in more
> places? I am not speaking about rotation just different field distribution. Is
> it possible the field lines to look like arrows that will show the direction of
> the field? Besides that the equipotential lines are really beautiful!
>
Johann,
Changing the base equation would certainly change results, but the code 
was set up to implement changes on each placed sphere. Though true that, 
due my hacking, the previous code did need to be changed throughout to 
stay lined up with by sphere changes. Suppose I was aiming to offer an 
example more than a complete solution.

Below is an updated version of the code through the contours part, 
modified so the charged sphere specifications are centralized - so it is 
easier to play with values and placements. I've added a couple of 
additional spheres to make the resultant image more interesting.

There are a thousand ways to further change & improve things, but I am 
going to leave the rest as an exercise for any users of the code.

Have fun.
Bill P.

//----------------------- V3 ------------------------
#version 3.7;
global_settings {
     assumed_gamma 1
     ambient_light srgb <1,1,1>
}
#declare White = srgbft <1,1,1,0,0>;
background {
     color White
}
#declare Camera00 = camera {
     orthographic
     location <0,0,-10>
     sky <0,1,0>
     right x*(image_width/image_height)
     look_at <0,0,0>
}
#declare Light00 = light_source {
     <50,150,-250>, White
}
#declare Grey05 = srgbft <0.05,0.05,0.05,0,0>;
#declare CylinderX = cylinder {
     <-1,0,0>, <1,0,0>, 0.005
     pigment { color Grey05 }
     no_shadow
}
#declare Grey95 = srgbft <0.95,0.95,0.95,0,0>;
#declare CylinderY = cylinder {
     <0,-1,0>, <0,1,0>, 0.005
     pigment { color Grey95 }
     no_shadow
}
#declare Grey50 = srgbft <0.5,0.5,0.5,0,0>;
#declare CylinderZ = cylinder {
     <0,0,-1>, <0,0,1>, 0.005
     pigment { color Grey50 }
     no_shadow
}
#declare Sphere00 = sphere { <0,0,0>, 1 }
#declare K = 1.0;
#declare Min_e = -1.0;
#declare Max_e = 1.0;
#declare Range_e = Max_e-Min_e;
#declare MidAdj_e = Range_e/2;
#declare MaxPlotRange = 10.0;
#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,vx,vy,vz,k,q,mag) {
 
Fn00((x/mag/abs(q))-(vx/mag/abs(q)),(y/mag/abs(q))-(vy/mag/abs(q)),(z/mag/abs(q))-(vz/mag/abs(q)),k,q)
}
#declare Radius02 = 1.0;
#declare Position02 = <2.5,0,0,0.0>;
#declare Fn02 = function (x,y,z) {
     #local vx=Position02.x; #local vy=Position02.y; #local 
vz=Position02.z; Fn01(x,y,z,vx,vy,vz,K,-1.0,Radius02)
}
#declare Radius03 = 1.0;
#declare Position03 = <-2.5,0,0,0.0>;
#declare Fn03 = function (x,y,z) {
     #local vx=Position03.x; #local vy=Position03.y; #local 
vz=Position03.z; Fn01(x,y,z,vx,vy,vz,K,1.0,Radius03)
}
#declare Radius04 = 0.5;
#declare Position04 = <0.0,2.0,0.0>;
#declare Fn04 = function (x,y,z) {
     #local vx=Position04.x; #local vy=Position04.y; #local 
vz=Position04.z; Fn01(x,y,z,vx,vy,vz,K,1.0,Radius04)
}
#declare Radius05 = 0.2;
#declare Position05 = <-0.4,-2.2,0.0>;
#declare Fn05 = function (x,y,z) {
     #local vx=Position05.x; #local vy=Position05.y; #local 
vz=Position05.z; Fn01(x,y,z,vx,vy,vz,K,-1.0,Radius05)
}
#declare FnAllCharges = function (x,y,z) {
     Fn02(x,y,z)+Fn03(x,y,z)+Fn04(x,y,z)+Fn05(x,y,z)
}
#declare FnAllChargesNormalized = function (x,y,z) {
 
(FnAllCharges(x*MaxPlotRange,y*MaxPlotRange,z*MaxPlotRange)+MidAdj_e)/Range_e
}
#declare FnPigmentAllCharges = function (x,y,z) {
     min(1,max(0,FnAllChargesNormalized(x,y,z)))
}
#declare Blue = srgbft <0,0,1,0,0>;
#declare Clear100 = srgbft <1,1,1,1,0>;
#declare Red = srgbft <1,0,0,0,0>;
#declare ColorMapField = color_map {
     [ 0 Blue ]
     [ 0.5 Clear100 ]
     [ 1 Red ]
}
#declare PigmentField = pigment {
     function { FnPigmentAllCharges(x,y,z) }
     color_map { ColorMapField }
}
#declare TextureField = texture {
     pigment { PigmentField }
}
#declare Grey80 = srgbft <0.8,0.8,0.8,0,0>;
#declare ColorMapSphere = color_map {
     [ 0 Blue ]
     [ 0.5 Grey80 ]
     [ 1 Red ]
}
#declare PigmentSphere = pigment {
     function { FnPigmentAllCharges(x,y,z) }
     color_map { ColorMapSphere }
}
#declare TextureSphere = texture {
     pigment { PigmentSphere }
}
#declare ObjSphere02 = object {
     object { Sphere00 }
     scale Radius02
     translate <Position02.x,Position02.y,Position02.z>
}
#declare ObjSphere03 = object {
     object { Sphere00 }
     scale Radius03
     translate <Position03.x,Position03.y,Position03.z>
}
#declare ObjSphere04 = object {
     object { Sphere00 }
     scale Radius04
     translate <Position04.x,Position04.y,Position04.z>
}
#declare ObjSphere05 = object {
     object { Sphere00 }
     scale Radius05
     translate <Position05.x,Position05.y,Position05.z>
}
#declare UnionAllSpheres = union {
     object { ObjSphere02 }
     object { ObjSphere03 }
     object { ObjSphere04 }
     object { ObjSphere05 }
     scale 1/MaxPlotRange
}
#declare ObjAllSpheres = object {
     object { UnionAllSpheres }
     texture { TextureSphere }
     no_shadow
}
#declare Magenta = srgbft <1,0,1,0,0>;
#declare ColorMapContour = color_map {
     [ 0 Clear100 ]
     [ 0.5-(0.5/pow(2,1))-0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,1))+0.000 Magenta ]
     [ 0.5-(0.5/pow(2,1))+0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,2))-0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,2))+0.000 Magenta ]
     [ 0.5-(0.5/pow(2,2))+0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,3))-0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,3))+0.000 Magenta ]
     [ 0.5-(0.5/pow(2,3))+0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,4))-0.005 Clear100 ]
     [ 0.5-(0.5/pow(2,4))+0.000 Magenta ]
     [ 0.5-(0.5/pow(2,4))+0.005 Clear100 ]
     [ 0.5-0.005 Clear100 ]
     [ 0.5+0.000 Magenta ]
     [ 0.5+0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,4))-0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,4))+0.000 Magenta ]
     [ 0.5+(0.5/pow(2,4))+0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,3))-0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,3))+0.000 Magenta ]
     [ 0.5+(0.5/pow(2,3))+0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,2))-0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,2))+0.000 Magenta ]
     [ 0.5+(0.5/pow(2,2))+0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,1))-0.005 Clear100 ]
     [ 0.5+(0.5/pow(2,1))+0.000 Magenta ]
     [ 0.5+(0.5/pow(2,1))+0.005 Clear100 ]
     [ 1 Clear100 ]
}
#declare PigmentContour = pigment {
     function { FnAllChargesNormalized(x,y,z) }
     color_map { ColorMapContour }
}
#declare TextureContour = texture {
     pigment { PigmentContour }
}
#macro Texture2Dslice_ListOf_0 ()
     texture { TextureContour }
     texture { TextureField }
#end
#declare Box00 = box {
     <-9.5,-9.5,-0.001>,<9.5,9.5,0.001>
}
#declare Obj2DSlice = object {
     object { Box00 }
     Texture2Dslice_ListOf_0()
}

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


Post a reply to this message

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