POV-Ray : Newsgroups : povray.newusers : How to: Sphere with 3D Electric Field Lines Server Time
11 May 2024 09:36:11 EDT (-0400)
  How to: Sphere with 3D Electric Field Lines (Message 7 to 16 of 26)  
<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: William F Pokorny
Subject: Re: How to: Sphere with 3D Electric Field Lines
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

From: Johann
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 27 Sep 2014 11:00:01
Message: <web.5426d061266802cb16298ca60@news.povray.org>
> Help 2.3.3.1 Blob Object
> Help 2.3.3.1.1 Component Types and Other New Features
> Help 3.4.5.1.1 Blob
>
>
> --
>
> Regards
>      Stephen

Thanks Stephen! I will have a look at it. Well as I mentioned above, I am brand
new to POV RAY and that means it will take some time to become familiar with POV
RAY philisophy, although I have some experience in programming.


Post a reply to this message

From: Johann
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 27 Sep 2014 11:40:00
Message: <web.5426d96c266802cb16298ca60@news.povray.org>
> 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.

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.

I completely understand how bothersome is when someone asks for a solution to
his problem without even to know how to use the tool. Therefore, I would like to
help on this direction. Below I have two sample codes, I found on the Internet
which need to be tweaked by someone with knowledge to give the expected result:

Example Nr.1:
// it creates a sphere with 200 random electric field lines
// it seems on the below code the electric field formula E=KQ/r^2 is not used
and instead it creates random lines around the sphere surface
#include "colors.inc"
light_source { <10,0,-1> color White shadowless }
light_source { <0,0,-10> color White shadowless }
camera {location <2,2,-5> look_at <0,0,0> }
sphere { <0,0,0>,0.4 pigment {Red} }
#declare R1=seed(0);
#declare R=2.5;
#declare c=0;
#while(c <= 300)
 #declare theta=pi*rand(R1);
#declare phi=2.0*pi*rand(R1);
#declare xp=R*sin(theta)*cos(phi);
#declare yp=R*sin(theta)*sin(phi);
#declare zp=R*cos(theta);
cylinder {<0,0,0>,<xp,yp,zp>,0.01 pigment {Orange}}
#declare c=c+1;
#end

If we could modify the above that will include clearly the electric field
formula (if possible to show field line direction), it will be of great help.
Then the second sample I need, it will be two spheres interacting with their
fields.

Example Nr.2 (Brilliant work by Paul Nylander):
//******************************************************************************************
//* Magnetic Field of a Solenoid, copyright by Paul Nylander, bugman123.com,
5/17/06
//* runtime: 1 minute
//******************************************************************************************

#declare mu0=1.25663706144e-6; #declare n=6; #declare R=0.01; #declare
dL=(4/3)*R; #declare r=R/4;
camera{location <13.65,0,16.25>*R look_at 0.4*R*x up -y right
x*image_width/image_height sky -y angle 25}
light_source{<0,0,8*R>,1}

//Solenoid
#include "golds.inc"
#declare begin=1; #declare x1=(0.25-n/2)*dL;
#while(x1<=(n/2-0.25)*dL)
 #declare theta=2*pi*(x1/dL+n/2); #declare p2=<x1,R*sin(theta),-R*cos(theta)>;
 sphere{p2,r texture{T_Gold_5A}} #if(!begin) cylinder{p1,p2,r
texture{T_Gold_1A}} #end
 #declare begin=0; #declare p1=p2; #declare x1=x1+0.005*dL;
#end

//Electromagnetic Field
#declare Sqr=function(X) {X*X};
#declare sign=function(i1) {1-2*floor(2*mod((i1-1)/2,n)/n)}; // i1<n1?1:-1
#declare I=function(i1) {sign(i1)}; // current
#declare xcoil=function(i1)
{(4/3)*R*(mod(i1-1,n)+0.5*floor(2*mod((i1-1)/2,n)/n)-0.5*(n-0.5))};
#declare B=function{(mu0/(2*pi))*sqrt( // magnetic field magnitude
 Sqr(sum(i1,1,2*n,I(i1)*(y-sign(i1)*R)/(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)*R))))+
 Sqr(sum(i1,1,2*n,I(i1)*(x-xcoil(i1))/(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)*R))))
)}
#declare
contours=function{(2+cos(0.06*pi*(sum(i1,1,2*n,I(i1)/sqrt(Sqr(x-xcoil(i1))+Sqr(y-sign(i1)*R))))))/3}
// magnetic field line contours
plane{<0,0,1>,0
 pigment{function{min(1,max(0,12000*B(x,y,0)*contours(x,y,0)))} color_map{
  [0 rgbt <0,0,1,1>] [0.25 rgbt <0,0,1,0.75>] [0.5 rgbt <1/3,0,1,0.5>] [0.75
rgbt <2/3,0.5,1,0.25>] [1 rgbt <1,1,1,0>]
 }}
 finish{ambient 2.25 reflection 0 diffuse 0 specular 0}
}


First of all the above requires to replace the solenoid function with a sphere,
the magnetic field induction with the Electric Field and to display the contours
in 3D space. Easy said than done (at least for me).

Anyone who is interested to see what I am looking for, just run the
above two examples which are really impressive and they will give you more to
think or inspire you.

I believe that when someone with some experience on POV RAY and having knowledge
of basic Physics, when he run the above two examples, it will become clearer of
what we are up to.

Bill and everybody thank you very much for your time so far!


Post a reply to this message

From: Stephen
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 27 Sep 2014 19:43:45
Message: <54274bb1$1@news.povray.org>
On 27/09/2014 15:57, Johann wrote:
> Thanks Stephen! I will have a look at it. Well as I mentioned above, I am brand
> new to POV RAY and that means it will take some time to become familiar with POV
> RAY philisophy, although I have some experience in programming.

Please do and if it works, let me know.

I know what you mean. Learning Blender showed me that working with 
meshes requires different approaches.
If you can programme then the world is your oyster. :-)

-- 

Regards
     Stephen


Post a reply to this message

From: Johann
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 05:15:00
Message: <web.5427d02a266802cb16298ca60@news.povray.org>
> Please do and if it works, let me know.
>
> I know what you mean. Learning Blender showed me that working with
> meshes requires different approaches.
> If you can programme then the world is your oyster. :-)
>
> --
>
> Regards
>      Stephen

Hi Stephen! Well I am actually not a professional programmer but I have some
experience with older programming tools not related to 3D Graphics. The problem
is that I do not have experience in creating 3D Graphics using a programming
language and especially no knowledge about modelling stuff. Anyway, as you may
probably saw above, I have two examples that I would like to be modified with
some help.

Maybe you noticed it with yourself, when we start learn programming, most of us
have something in the back of our head that we like to develop. This means,
having a goal is the trigger to learn a programming language. If you just start
to learn a programming language without plan, then 99% you will abandon before
you even start.

What is all I am asking is with the help of the group to tweak the above sample
codes for the Electric field where the resulting rendered images are those I
would like to have (the displayed result in both examples). I am interested in
new
ideas in Physics (the plan) those will trigger my interest to learn POV RAY
(think a trap with a cheese and a mouse walking around it), otherwise I am not
interested. Why, I will not be interested?Since, I do not have drawing and art
skills to spend my time with POV RAY just for the sake of creativity.

I really admire those skilled and talented people who create such amazing works
with POV RAY but I cannot follow since I do not have such creative skills as
also it is not my goal. So for once more, if the group could help me on the
above, certainly I will learn more and it will start to have fun for me. Without
having fun or like what you are doing, better not do it.

In any case, thanks for your post!

Johann


Post a reply to this message

From: Thomas de Groot
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 07:03:34
Message: <5427eb06$1@news.povray.org>
The two examples and especially the second, are interesting,a nd just 
for that I thank you. Unfortunately, I have no skills in physics to be 
able to really help you although I shall think a bit more about how 
things could be achieved. I have a hunch that it should not be too 
difficult, but then being a lay person in this...;-)

Thomas


Post a reply to this message

From: Johann
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 09:50:01
Message: <web.54280f80266802cb16298ca60@news.povray.org>
Thomas de Groot <tho### [at] degrootorg> wrote:
> The two examples and especially the second, are interesting,a nd just
> for that I thank you. Unfortunately, I have no skills in physics to be
> able to really help you although I shall think a bit more about how
> things could be achieved. I have a hunch that it should not be too
> difficult, but then being a lay person in this...;-)
>
> Thomas

Hi Thomas!
I believe the first example is very simple, it could be possible to be modified
with ease. The second one although most impressive that is the most beautiful
rendered image of a field I have seen in my life so far, it will be a little
more difficult to modify but not impossible. What requires is someone with an
idea or better with some skill about how to render functions and especially
Physics Field functions on POV RAY. On a previous post Bill shared a POV RAY
code but it is too slow and it is not exactly what I need. You may notice on his
sample he uses clearly the Electric Field function but the total result is poor
in quality and performance.

If you search on the Internet you may find all the masterpieces of the world
with many sample POV RAY code but almost none to share the POV RAY Code for
electromagnetic fields. Those two examples I shared, are the only found on the
net. Strange, isn't it?

Thanks for your post!

Johann


Post a reply to this message

From: Thomas de Groot
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 10:00:43
Message: <5428148b$1@news.povray.org>
On 28-9-2014 15:45, Johann wrote:
> Hi Thomas!
> I believe the first example is very simple, it could be possible to be modified
> with ease. The second one although most impressive that is the most beautiful
> rendered image of a field I have seen in my life so far, it will be a little
> more difficult to modify but not impossible. What requires is someone with an
> idea or better with some skill about how to render functions and especially
> Physics Field functions on POV RAY. On a previous post Bill shared a POV RAY
> code but it is too slow and it is not exactly what I need. You may notice on his
> sample he uses clearly the Electric Field function but the total result is poor
> in quality and performance.
>
> If you search on the Internet you may find all the masterpieces of the world
> with many sample POV RAY code but almost none to share the POV RAY Code for
> electromagnetic fields. Those two examples I shared, are the only found on the
> net. Strange, isn't it?
>
> Thanks for your post!
>

As I said, my physics are poor and I do not know what to visualize under 
an electric field. Does that resemble a magnetic field like the one 
around the Earth? For the first example at least that would mean toruses 
in 3D space.

Thomas


Post a reply to this message

From: Thomas de Groot
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 10:16:26
Message: <5428183a$1@news.povray.org>
Hmm. I ran Bill's example and while some parts could readily be 
represented by toruses, all is not that simple... Maybe parametric 
objects but those are reputedly extremely slow. Isosurfaces are my best 
guess at the moment.

Thomas


Post a reply to this message

From: Johann
Subject: Re: How to: Sphere with 3D Electric Field Lines
Date: 28 Sep 2014 13:40:01
Message: <web.5428472b266802cb16298ca60@news.povray.org>
> As I said, my physics are poor and I do not know what to visualize under
> an electric field. Does that resemble a magnetic field like the one
> around the Earth? For the first example at least that would mean toruses
> in 3D space.
>
> Thomas

Hi Thomas! I am also not a physicist but the way to find a solution is to use
the first example which is simpler. I think what is needed is to attach in a way
the value of the amplitude (E=K*q/r^2) to the cylinder length. The formula of
the electric field is just a function like y=1/r^2. As I can imagine it probably
cannot work like this but using y=1/r^2 to create a color gradient with distance
as a first attempt.

I think you are right, the solution could be isosurfaces (I suppose they are
similar to contours or to equipotential surfaces) using the y=1/r^2 as a first
attempt. If you can find a solution on this, it would be greatly appreciated.

Ioannis


Post a reply to this message

<<< Previous 6 Messages Goto Latest 10 Messages Next 10 Messages >>>

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