POV-Ray : Newsgroups : povray.advanced-users : Sphere placement issues Server Time
28 Jul 2024 18:22:49 EDT (-0400)
  Sphere placement issues (Message 1 to 9 of 9)  
From: Oldstench
Subject: Sphere placement issues
Date: 21 Mar 2004 22:01:01
Message: <e9ls5054rc1rs76j1p493oi862o85vpgrb@4ax.com>
Ok math wizards... 

This scene is just a test of pyramidal sphere structures, but I am
having a small issue. If I want the topmost sphere to appear as if it
is laying on top of the 4 sphere base, what kind of math do I need to
do to get the sphere to be placed in exactly the right position
vertically?

The closest I can get is to move the sphere up by twice the radius +
the radius / pi. This is incorrect, however. 

If anyone knows the answer (I know you do!) please not only tell me
what the solution is, but could you explain why? (As long as that is
not too much trouble.)

Here is the test scene:

global_settings {
  assumed_gamma 1
}

#default {
  finish {
    ambient 1
  }
}

#declare mcx = .25;
#declare mcy = .25;

camera {
  orthographic
  location <mcx,mcy,-1>
  look_at <mcx,mcy,0>
  right x*image_width/image_height
  angle 75
}

#declare inter = 0;
#declare rad = 0.25;

#if (inter)
intersection {
#end
  union {
    sphere {
      0, rad
      pigment {
        color rgbt <0,0,1,.7>
      }
    }
    
    sphere {
      0, rad
      pigment {
        color rgbt <0,0,1,.7>
      }
      translate x*rad*2
    }
  }
  
  sphere {
    0, rad
    pigment {
      color rgbt <1,0,0,.7>
    }
    translate <rad, 2*rad - (rad/pi), 0>
  }
#if (inter)
}  
#end

------------------------------------
Thanks


Post a reply to this message

From: Oldstench
Subject: Re: Sphere placement issues
Date: 21 Mar 2004 22:10:50
Message: <3ams501unqs4oqmngauhnoevkkk78tts5g@4ax.com>
On Sun, 21 Mar 2004 22:01:59 -0500, Oldstench <sry### [at] nocom> wrote:
>Snip<

>The closest I can get is to move the sphere up by twice the radius +
>the radius / pi. This is incorrect, however. 

Oops...that should read twice the radius - the radius / pi.
Sorry


Post a reply to this message

From: Christopher James Huff
Subject: Re: Sphere placement issues
Date: 21 Mar 2004 22:37:43
Message: <cjameshuff-D9AB84.22375521032004@news.povray.org>
In article <e9ls5054rc1rs76j1p493oi862o85vpgrb@4ax.com>,
 Oldstench <sry### [at] nocom> wrote:

> Ok math wizards... 

Will I do?


> This scene is just a test of pyramidal sphere structures, but I am
> having a small issue. If I want the topmost sphere to appear as if it
> is laying on top of the 4 sphere base, what kind of math do I need to
> do to get the sphere to be placed in exactly the right position
> vertically?
...
> If anyone knows the answer (I know you do!) please not only tell me
> what the solution is, but could you explain why? (As long as that is
> not too much trouble.)

This is just a tetrahedron. You can easily put the spheres in the proper 
position relative to each other:

Take a cube from <-1,-1,-1> to < 1, 1, 1>.
Place a sphere at four corners of the cube, on opposing diagonals. For 
example: <-1,-1,-1>, < 1, 1,-1>, <-1, 1, 1>, < 1,-1, 1>.
You now have a sphere centered at each corner of the tetrahedron. The 
point where each sphere meets one of its neighbors is the midpoint of 
the cube side they share. Thus, the radius is half the length of the 
diagonal: sqrt(2)/2. Scale the centers by the reciprocal of this to get 
a tetrahedron with unit spheres.

This isn't oriented very conveniently for a pyramid. However, it 
shouldn't be too hard to work out the distance of one sphere center from 
the plane of the other sphere centers, which will give you the 
information you need. Take a vector from the origin to one of the 
spheres as the plane normal. The height of the tetrahedron the spheres 
are placed on will be the length of that vector plus the distance of one 
of the other points to the plane defined by it. Hint: dot product.

I hope that's enough to get you started. It's probably not the best way, 
but it seems simplest.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Mark Weyer
Subject: Re: Sphere placement issues
Date: 22 Mar 2004 06:34:25
Message: <405ED1B7.5070000@informatik.uni-freiburg.de>
> This scene is just a test of pyramidal sphere structures, but I am
> having a small issue. If I want the topmost sphere to appear as if it
> is laying on top of the 4 sphere base, what kind of math do I need to
> do to get the sphere to be placed in exactly the right position
> vertically?

The solution is: Pythagoras

I will assume sphere radii of 1.

Your scene suggests that you want 2 base spheres at positions <0,0,0>
and <2,0,0>. Then the third must be at <1,y,0>, where y is such that
the spheres touch. The do touch, if they are exactly 2 apart, that is
if (1-0)^2+(y-0)^2=2^2, or, equivalently, y=sqrt(3).

If you want, like Christopher James assumes, 3 base spheres, then you
want to place those as above, but in the xz-plane, that is as positions
<0,0,0>, <2,0,0>, and <1,0,sqrt(3)>. Now before we look for the fouth
sphere, let us find the center of the triangle formed by the three
spheres so far. It will be <1,0,z> for some z, so that is is equally
far apart from each of the first two spheres. The requirement for being
as far apart in turn from the third sphere is
   (1-0)^2+(z-0)^2 = (1-1)^2+(sqrt(3)-z)^2
that is
   1+z^2 = 3-2*sqrt(3)*z+z^2
that is
   2*sqrt(3)*z = 2
that is
   z = sqrt(3)/3
The forth sphere must be above this center, so it has coordinates
<1,y,sqrt(3)/3>. Now we are looking for y such that the distance from
the other 3 spheres (say the first) is 2, that is
   (1-0)^2+(y-0)^2+(sqrt(3)/3)^2=2^2
that is
   1+y^2+1/3=4
that is
   y^2=8/3
that is
   y=sqrt(8/3)

If you want, like the term pyramid suggests, 4 base spheres, then
these will be at positions <0,0,0>, <2,0,0>, <0,0,2>, and <2,0,2>. The
fifth sphere will be at <1,y,1> such that its distance from the first
is 2, that is (1-0)^2+(y-0)^2+(1-0)^2=2^2, that is y^2=2, that is
y=sqrt(2).

Be aware of computational flaws I might have made.


-- 
merge{#local i=-11;#while(i<11)#local
i=i+.1;sphere{<i*(i*i*(.05-i*i*(4e-7*i*i+3e-4))-3)10*sin(i)30>.5}#end
pigment{rgbt 1}interior{media{emission x}}hollow}//  Mark Weyer


Post a reply to this message

From: Marvin Taylor
Subject: Re: Sphere placement issues
Date: 22 Mar 2004 14:05:07
Message: <405f38e3$1@news.povray.org>
Oldstench wrote:
> Ok math wizards... 
> 
> This scene is just a test of pyramidal sphere structures, but I am
> having a small issue. If I want the topmost sphere to appear as if it
> is laying on top of the 4 sphere base, what kind of math do I need to
> do to get the sphere to be placed in exactly the right position
> vertically?
> 
> The closest I can get is to move the sphere up by twice the radius +
> the radius / pi. This is incorrect, however. 
> 
> If anyone knows the answer (I know you do!) please not only tell me
> what the solution is, but could you explain why? (As long as that is
> not too much trouble.)

If each row (aside from the top) is set up on a rectangular grid, then 
the answer you want is rad*sqrt(2).

Christopher - I did not really follow your response, although I think 
you said the same thing:
 > the radius is half the length of the diagonal: sqrt(2)/2.
 > Scale the centers by the reciprocal of this

However, doesn't "tetrahedron" apply only to a 3 sided "pyramid"?  He 
was asking for a 4-sided one -- is there a mathematical term for that 
particular polyhedron?

Meanwhile Oldstench, try the scene below, and note that 'yy' is the 
height offset which is incremented by R*sqrt(2).   Change 'N' to get 
taller or shorter pyramids.

Marvin

---------------------------
// Try with: +KF1 +KFF16 +W400 +H300

// 4-sided pyramid of balls:
light_source { <0,100,-50>, 1.0 }
light_source { <20,100,10>, 1.0 shadowless }
light_source { <20,-50,10>, 1.0 shadowless }

#declare R = 1;  // Radius of balls.
#declare N = 4;  // number of layers

camera {
  location R*N*<10*sin(clock*2*pi),3,10*cos(clock*2*pi)>
  look_at y*R*N   angle 30
}

plane {y,0 pigment{rgb<0,0,1>}}

#macro show(tag,var) concat(" ",tag,"=",str(var,4,3)) #end
#local yy = R;
#local ii = N;
#while (ii>0)
   #local xx = -R*(ii-1);
   #local aa = 0; #while (aa<ii) #local aa=aa+1;
     #local zz = -R*(ii-1);
     #local bb = 0; #while (bb<ii) #local bb=bb+1;
       sphere { <xx,yy,zz>, R  pigment {rgb<.8.8.8>}}
       #local zz = zz + 2*R;
     #end /* bb */
     #local xx = xx + 2*R;
   #end /* aa */
   #local yy = yy + R*sqrt(2);
#local ii=ii-1; #end /* ii */


Post a reply to this message

From: Oldstench
Subject: Re: Sphere placement issues
Date: 22 Mar 2004 19:23:59
Message: <ds0v50himqspueer4hpaqu3m4nniqll2e0@4ax.com>
On Sun, 21 Mar 2004 22:37:55 -0500, Christopher James Huff
<cja### [at] earthlinknet> wrote:

><Snip lots of stuff I do not understand><

Well, no one has ever accused me of being a math wiz, and this answer
has certainly proven that! I can not follow your answer. But thanks
anyway!


Post a reply to this message

From: Oldstench
Subject: Re: Sphere placement issues
Date: 22 Mar 2004 19:28:47
Message: <k21v5051frudv40pq8do6mhn01nvr5tasf@4ax.com>
On Mon, 22 Mar 2004 12:44:55 +0100, Mark Weyer
<wey### [at] informatikuni-freiburgde> wrote:

>> This scene is just a test of pyramidal sphere structures, but I am
>> having a small issue. If I want the topmost sphere to appear as if it
>> is laying on top of the 4 sphere base, what kind of math do I need to
>> do to get the sphere to be placed in exactly the right position
>> vertically?
>
>The solution is: Pythagoras
>
>I will assume sphere radii of 1.
>
>Your scene suggests that you want 2 base spheres at positions <0,0,0>
>and <2,0,0>. Then the third must be at <1,y,0>, where y is such that
>the spheres touch. The do touch, if they are exactly 2 apart, that is
>if (1-0)^2+(y-0)^2=2^2, or, equivalently, y=sqrt(3).
>
>If you want, like Christopher James assumes, 3 base spheres, then you
>want to place those as above, but in the xz-plane, that is as positions
><0,0,0>, <2,0,0>, and <1,0,sqrt(3)>. Now before we look for the fouth
>sphere, let us find the center of the triangle formed by the three
>spheres so far. It will be <1,0,z> for some z, so that is is equally
>far apart from each of the first two spheres. The requirement for being
>as far apart in turn from the third sphere is
>   (1-0)^2+(z-0)^2 = (1-1)^2+(sqrt(3)-z)^2
>that is
>   1+z^2 = 3-2*sqrt(3)*z+z^2
>that is
>   2*sqrt(3)*z = 2
>that is
>   z = sqrt(3)/3
>The forth sphere must be above this center, so it has coordinates
><1,y,sqrt(3)/3>. Now we are looking for y such that the distance from
>the other 3 spheres (say the first) is 2, that is
>   (1-0)^2+(y-0)^2+(sqrt(3)/3)^2=2^2
>that is
>   1+y^2+1/3=4
>that is
>   y^2=8/3
>that is
>   y=sqrt(8/3)
>
>If you want, like the term pyramid suggests, 4 base spheres, then
>these will be at positions <0,0,0>, <2,0,0>, <0,0,2>, and <2,0,2>. The
>fifth sphere will be at <1,y,1> such that its distance from the first
>is 2, that is (1-0)^2+(y-0)^2+(1-0)^2=2^2, that is y^2=2, that is
>y=sqrt(2).
>
>Be aware of computational flaws I might have made.

Thanks a lot! I really appreciate this, and now I will dust my
Geometry 101 section of my brain off and put this info to work.


Post a reply to this message

From: Oldstench
Subject: Re: Sphere placement issues
Date: 22 Mar 2004 19:50:04
Message: <2f2v50tmi3g060tqtmrui3p9d41rmnonoo@4ax.com>
On Mon, 22 Mar 2004 12:06:08 -0700, Marvin Taylor
<pov### [at] maltasoftcom> wrote:

And I appreciate your help as well...danke!


Post a reply to this message

From: Christopher James Huff
Subject: Re: Sphere placement issues
Date: 24 Mar 2004 23:22:31
Message: <cjameshuff-BD85D7.23224924032004@news.povray.org>
In article <ds0v50himqspueer4hpaqu3m4nniqll2e0@4ax.com>,
 Oldstench <sry### [at] nocom> wrote:

> ><Snip lots of stuff I do not understand><
> 
> Well, no one has ever accused me of being a math wiz, and this answer
> has certainly proven that! I can not follow your answer. But thanks
> anyway!

Well, I tried...what part(s) didn't make sense?

Anyway, I was thinking of a three sided pyramid...four triangular faces 
including the base. If you're doing a four sided pyramid, consider the 
fact that the top sphere and two opposing corner spheres form a right 
triangle, with the two equal sides being equal to twice the radius of 
the spheres. The height of the top sphere is the altitude of this 
triangle. Through this, you can figure out that the distance of each 
sphere from the center of the base is sqrt(2)*sphere radius (using the 
Pythagorean rule).

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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