POV-Ray : Newsgroups : povray.advanced-users : Can't figure out a formula! Server Time
27 Nov 2024 00:50:11 EST (-0500)
  Can't figure out a formula! (Message 1 to 4 of 4)  
From: Jeff Lee
Subject: Can't figure out a formula!
Date: 19 May 1999 13:22:04
Message: <3742e52c.0@news.povray.org>
Hi there,

I have a sinking feeling that this is a pathetically basic question,
though I know the advanced users have the best background to answer it,
which is why I'm posting it here:

I'm trying to write a macro that takes three points, and creates a plane
which is rotated and translated to intersect all three points.  Now, I
think I've figured out how to get the normal of the triangle described
by the points, but I'm not sure exactly how to turn that into an angle.

Here's what I've got so far:

#macro safeatan(a,b) #if (a|b) degrees(atan2(a,b)) #else 0.0 #end #end

#macro MakePlane( a, b, c )
  #local n = vnormalize( vcross( b-a, c-a ));
  #debug concat( "Normal: <", str(n.x,0,5), ",", str(n.y,0,5),",",
str(n.z,0,5),">\n" )

  #local d  = <safeatan(n.z,n.y),      // This is the bit that needs
               180+safeatan(n.x,n.z),  //  help.
               -safeatan(n.x,n.y)>;

  #debug concat( "Angle: <", str(d.x,0,5), ",", str(d.y,0,5),",",
str(d.z,0,5),">\n" )

  plane { y, 0 rotate d translate a }
#end

Any help would be greatly appreciated.


-- 
Jeff Lee         shi### [at] gatenet         http://www.gate.net/~shipbrk/


Post a reply to this message

From: Ron Parker
Subject: Re: Can't figure out a formula!
Date: 19 May 1999 15:44:51
Message: <374306a3.0@news.povray.org>
On Wed, 19 May 1999 16:38:53 GMT, Jeff Lee wrote:
>I'm trying to write a macro that takes three points, and creates a plane
>which is rotated and translated to intersect all three points.  Now, I
>think I've figured out how to get the normal of the triangle described
>by the points, but I'm not sure exactly how to turn that into an angle.

You don't need an angle.  You don't need to rotate or translate.
A plane is defined by its normal and offset, so just find those:

This is untested, but if it's wrong it's probably just by a sign 
somewhere.

#macro MakePlane(a,b,c) 
  #local n=vnormalize(vcross((b)-(a),(c)-(a)));
  #local o=vdot((a),n);
  plane {n,o}
#end


Post a reply to this message

From: Jeff Lee
Subject: Re: Can't figure out a formula!
Date: 19 May 1999 16:48:03
Message: <37431573.0@news.povray.org>
par### [at] fwicom (Ron Parker) wrote:
>
> You don't need an angle.  You don't need to rotate or translate.

Unfortunately, I neglected to mention that I need to align a texture to
the plane (I omitted that from the code snippet for clarity), so I still
do need the information.  I think I figured out what I did wrong,
though; it looks like this makes it work:

#macro safeatan(a,b) #if (a|b) degrees(atan2(a,b)) #else 0.0 #end #end

#macro MakePlane( a, b, c )
  #local n  = vnormalize( vcross( b-a, c-a ));
  #local v1 = -(90-(safeatan(n.y,sqrt(n.z*n.z+n.x*n.x))));
  #local v2 = (safeatan(n.x,n.z))-180;
  #local d  = <v1,v2,0>;
  plane { y, 0 texture { whatever } rotate d translate c }
#end



-- 
Jeff Lee         shi### [at] gatenet         http://www.gate.net/~shipbrk/


Post a reply to this message

From: Nieminen Mika
Subject: Re: Can't figure out a formula!
Date: 20 May 1999 11:49:34
Message: <374420fe.0@news.povray.org>
Ron Parker <par### [at] fwicom> wrote:
:   #local n=vnormalize(vcross((b)-(a),(c)-(a)));

  You don't need to normalize the vector since the length of the vector
doesn't matter. Normalizing only makes parsing slower.
  Of course if you use the normal vector for example in a matrix to
transform the object/texture then you need to normalize it.

  Btw. The matrix transformation calculated from the normal vector is
much better then using the angle. For more info see:
http://www.erols.com/vansickl/matrix.htm

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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