POV-Ray : Newsgroups : povray.newusers : How to: Sphere with 3D Electric Field Lines : Re: How to: Sphere with 3D Electric Field Lines Server Time
12 May 2024 06:04:13 EDT (-0400)
  Re: How to: Sphere with 3D Electric Field Lines  
From: William F Pokorny
Date: 28 Sep 2014 15:09:50
Message: <54285cfe$1@news.povray.org>
On 09/27/2014 11:39 AM, Johann wrote:
>
> Thanks Bill for your proposal! Just a few minutes ago POV RAY started to render
> the image and it took about 14 minutes for 320x240 AA 0.3. I believe that what I
> am looking for is relative easy and not so complicated.
>
Johann & all,

A memory came back to me a bit ago of work on some vector analysis 
functions a decade or more back. Sure enough in Pov-Ray's math.inc there 
is a collection of functions written by Christoph Hormann and Tor Olav 
Kristensen. Also an example  povray file in

scenes/incdemo/f_guncradient.pov.

Stealing code almost directly from func_gradient.pov and using our 
functions to control pigments instead of generate isosurfaces we can get 
something which runs quite a lot faster.

While likely not as artistic an output as I think you want, the result 
at least touches on all the elements I believe you seek.

I'll post an image generated by the code below to p.b.images shortly.

Bill P.

//-------------- e_static_v2.pov --------------------
#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 Red = srgbft <1,0,0,0,0>;
#declare Blue = srgbft <0,0,1,0,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,_X,_Y,_Z,k,q) {
     Fn00(x-_X,y-_Y,z-_Z,k,q)
}
#declare Fn02 = function (x,y,z) {
     Fn01(x,y,z,2.5,0.0,0.0,1.0,-1.0)
}
#declare Fn03 = function (x,y,z) {
     Fn01(x,y,z,-2.5,0.0,0.0,1.0,1.0)
}
#declare Fn04 = function (x,y,z) {
     Fn02(x,y,z)+Fn03(x,y,z)
}
#declare Fn04normalized = function (x,y,z) {
     (Fn04(x*10,y*10,z*10)+1.0)/2.001
}
#declare Clear100 = srgbft <1,1,1,1,0>;
#declare ColorMapField = color_map {
     [ 0 Blue ]
     [ 0.5 Clear100 ]
     [ 1 Red ]
}
#declare PigmentField = pigment {
     function { Fn04normalized(x,y,z) }
     color_map { ColorMapField }
}
#declare TextureField = texture {
     pigment { PigmentField }
}
#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 { Fn04normalized(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 Sphere00 = sphere { <-0.25,0,0>, 0.1
     pigment { color Red }
     no_shadow
}
#declare Sphere01 = sphere { <0.25,0,0>, 0.1
     pigment { color Blue }
     no_shadow
}
#declare Obj2DSlice = object {
     object { Box00 }
     Texture2Dslice_ListOf_0()
}

//---
camera { Camera00 }
light_source { Light00 }
object { Sphere00 }
object { Sphere01 }
object { Obj2DSlice }


//--------------- Code below from scenes/incdemo/func_gradient.pov
#include "math.inc"
#declare PosX=-1.0;
#declare Spacing=0.018; // 0.018

union {
   #while (PosX < 1.0)
     #declare PosY=-0.5;
       #while (PosY < 0.5)
         #declare Pos=<PosX, PosY, 0>;
         #declare Vgrd=vGradient(Fn04normalized, Pos);
         #declare Vgrd=<Vgrd.x, Vgrd.y, 0>*0.1;
         #if (vlength(Vgrd)<0.300)
           cylinder {
             <PosX, PosY, 0>-Vgrd*0.105,
             <PosX, PosY, 0>+Vgrd*0.105,
             0.001
             texture {
               pigment { color srgb y*Gradient_Length(Fn04normalized, 
Pos)*0.25 }
             }
           }
         #end
         #declare PosY=PosY+Spacing;
       #end
     #declare PosX=PosX+Spacing;
   #end
}


Post a reply to this message

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