POV-Ray : Newsgroups : povray.general : Rotations... Server Time
20 Nov 2024 12:24:41 EST (-0500)
  Rotations... (Message 1 to 6 of 6)  
From: Ben Chambers
Subject: Rotations...
Date: 6 Aug 2001 20:41:19
Message: <3b6f392f$1@news.povray.org>
OK, my brain must be really fried, because I can't
think up the answer to this...

I have a vector which is perpendicular to a plane.
From this vector, how should I rotate an object so
that it lies in the plane?  The vector is represented
by a point along that axis.

...Chambers


Post a reply to this message

From: Margus Ramst
Subject: Re: Rotations...
Date: 6 Aug 2001 22:45:00
Message: <3B6F2C11.A54195C8@peak.edu.ee>
Ben Chambers wrote:
> 
> I have a vector which is perpendicular to a plane.
> From this vector, how should I rotate an object so
> that it lies in the plane?  The vector is represented
> by a point along that axis.
> 

Not sure what you need, but you might want to try John VanSickle's
Reorient macro:

#macro Reorient(Axis1,Axis2)
        #local vX1=vnormalize(Axis1);
        #local vX2=vnormalize(Axis2);
        #local vY=vnormalize(vcross(vX1,vX2));
        #local vZ1=vnormalize(vcross(vX1,vY));
        #local vZ2=vnormalize(vcross(vX2,vY));
        matrix < vX1.x, vY.x,vZ1.x, vX1.y,vY.y,vZ1.y, vX1.z,vY.z, vZ1.z,
0,0,0 >
        matrix < vX2.x,vX2.y,vX2.z,  vY.x,vY.y, vY.z, vZ2.x,vZ2.y,vZ2.z,
0,0,0 >
#end

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: Ben Chambers
Subject: Re: Rotations...
Date: 6 Aug 2001 23:58:06
Message: <3b6f674e@news.povray.org>
"Margus Ramst" <mar### [at] peakeduee> wrote in message
news:3B6F2C11.A54195C8@peak.edu.ee...
> Not sure what you need, but you might want to try John VanSickle's
> Reorient macro:
>
> #macro Reorient(Axis1,Axis2)
>         #local vX1=vnormalize(Axis1);
>         #local vX2=vnormalize(Axis2);
>         #local vY=vnormalize(vcross(vX1,vX2));
>         #local vZ1=vnormalize(vcross(vX1,vY));
>         #local vZ2=vnormalize(vcross(vX2,vY));
>         matrix < vX1.x, vY.x,vZ1.x, vX1.y,vY.y,vZ1.y, vX1.z,vY.z, vZ1.z,
> 0,0,0 >
>         matrix < vX2.x,vX2.y,vX2.z,  vY.x,vY.y, vY.z, vZ2.x,vZ2.y,vZ2.z,
> 0,0,0 >
> #end

Hmm... neat, but I can't seem to make it work...
Ok, I have here an object:

sphere {
 0,1
 scale <5,1,5>
}

I also have three points on a plane (lets call them
p1,p2,p3).  I'd like to have this flattened sphere
oriented on the plane...  Maybe I'm just braindead
tonight, but the reorient macro didn't do it for
me...

Thanks in advance...

...Chambers


Post a reply to this message

From: Jérôme Grimbert
Subject: Re: Rotations...
Date: 7 Aug 2001 02:11:36
Message: <3B6F8712.3DA22325@atosorigin.com>
Ben Chambers wrote:
> 
> OK, my brain must be really fried, because I can't
> think up the answer to this...
> 
> I have a vector which is perpendicular to a plane.
> From this vector, how should I rotate an object so
> that it lies in the plane?  The vector is represented
> by a point along that axis.
> 
> ...Chambers

Looks like you have the same question that I had : rotation
around an arbitrary vector.
I do not remember if I asked in p.g or p.a-u, but 
you should find the answer in the mid-june/mid-july 2001 posts.

There is two solutions for you: either a transform matrix, 
or a patch with a keyword.


Post a reply to this message

From: Margus Ramst
Subject: Re: Rotations...
Date: 7 Aug 2001 05:30:48
Message: <3B6F8B2E.F2056CFD@peak.edu.ee>
Ben Chambers wrote:
> 
> Hmm... neat, but I can't seem to make it work...
> Ok, I have here an object:
> 
> sphere {
>  0,1
>  scale <5,1,5>
> }
> 
> I also have three points on a plane (lets call them
> p1,p2,p3).  I'd like to have this flattened sphere
> oriented on the plane...  Maybe I'm just braindead
> tonight, but the reorient macro didn't do it for
> me...
> 

If the plane is described by 3 points, you first need the normal vector
of the plane:

Normal=vnormalize(vcross(p2-p1,p3-p1))

and the distance along that normal:

Distance=vdot(p1,Normal)

Now to align your flattened sphere with the plane, using the Reorient
macro:

sphere{
  0,1
  scale <5,1,5>
  Reorient(y,Normal)
  translate Normal*Distance
}

This is untested, but as far as I can see, should work.

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Rotations...
Date: 7 Aug 2001 11:32:54
Message: <3B700B1D.3DF5ED5F@hotmail.com>
Ben Chambers wrote:
...
> I also have three points on a plane (lets call them
> p1,p2,p3).  I'd like to have this flattened sphere
> oriented on the plane...  Maybe I'm just braindead
> tonight, but the reorient macro didn't do it for
> me...
...

Hello Ben

See my suggestion code below.
I hope it does what you want.

Best regards
from Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2001 by Tor Olav Kristensen
// mailto:tor### [at] hotmailcom
// http://www.crosswinds.net/~tok
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.1;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

// Define a macro that does the same as 
// John VanSickle's Reorient macro.
// (But with a slightly different method.)

#macro ReorientMatrix(vAxis1, vAxis2)

  #local v1 = vnormalize(vAxis1);
  #local v2 = vnormalize(vAxis2);
  #local vU = vcross(v1, v2);
  #local Dot = vdot(v1, v2);
  #local v0 = vnormalize(vU);
  #local vW = (1 - Dot)*v0;

  matrix <
    v0.x*vW.x + Dot,  v0.x*vW.y + vU.z, v0.x*vW.z - vU.y,
    v0.y*vW.x - vU.z, v0.y*vW.y + Dot,  v0.y*vW.z + vU.x,
    v0.z*vW.x + vU.y, v0.z*vW.y - vU.x, v0.z*vW.z + Dot,
    0,                0,                0
  >
  
#end // macro ReorientMatrix

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

// Define 3 points that lies on the plane
#declare p1 = <1, 2, 3>;
#declare p2 = <2, -1, -1>;
#declare p3 = <-1, 0, 1>;

// Show the 3 points
sphere { p1, 0.2 pigment { color Red } }
sphere { p2, 0.2 pigment { color Green } }
sphere { p3, 0.2 pigment { color Blue } }

// Calculate a normal vector for the plane
#declare vNormal = vnormalize(vcross(p2 - p1, p3 - p1));

// Calculate the common transformations 
#declare TiltAndTranslate =
transform {
  ReorientMatrix(y, vNormal)
  translate (p1 + p2 + p3)/3
// See note 1 below for other translate statements
// that can replace the line above.
}


// Then define your other stuff

#declare YourPlane =
plane {
  y, 0
  pigment { color Grey }
// See note 2 below
}

#declare YourSphere =
sphere {
  <0, 0, 0>, 1
  scale <5, 1, 5>
//  scale 1/4 // Uncomment if you want to see all the 3 points
  pigment { color Yellow }
}


// And transform it into place

object {
  YourPlane
  transform TiltAndTranslate
}

object {
  YourSphere
  transform TiltAndTranslate
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

light_source { <-2, 20, -1>*5 color White }

camera {
  location <1, 3, 2>*3
  look_at <0, -1, 0>
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =
/*

Note 1:

Here are some alternate translate
statements that also will work:

translate vdot(p1, vNormal)*vNormal
translate vdot(p2, vNormal)*vNormal
translate vdot(p3, vNormal)*vNormal
translate p1
translate p2
translate p3
translate (p1 + p2)/2
translate (p1 + p3)/2
translate (p2 + p3)/2
translate (p1 + p2 + p3)/3
...and so on...


Note 2:

It's sometimes easier to work with 
a disk instead of a plane. E.g.:

disc {
  <0, 0, 0>, y, 10
  transform TiltAndTranslate
  pigment { color Grey }
}

*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =


Post a reply to this message

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