POV-Ray : Newsgroups : moray.win : Local coordinates? Server Time
3 Jul 2024 00:51:22 EDT (-0400)
  Local coordinates? (Message 1 to 9 of 9)  
From: Timothy R  Cook
Subject: Local coordinates?
Date: 5 Dec 2001 10:07:23
Message: <3C0E37A2.4E2BAA6@scifi-fantasy.com>
Is there a way to rotate an object around its local coordinate
axes?  What I have is this:

Box
scale  [ 34.000  10.000  60.000]
rotate [  5.000 -53.975   0.000]
transl [-44.000  21.000  -8.000]
  local coords
scale  [  1.000   1.000   1.000]
rotate [  0.000   0.000   0.000]
transl [ -1.000   1.000   0.000]

I am trying to make it intersect points
     A [-32.000   0.000  76.000]
     B [-88.000  16.000 -40.000]
     C [  0.000  26.000  24.000]
to difference it from an object.  I have it rotated to where
I want it XY, but when I try rotating it around its Z axis,
it rotates around the WORLD axis, not its own, and the local
coordinate rotation just shears the box at whatever angle,
not at all what I want.

So, what do I do to get the effect I want?  If I need to
rotate it on the real-world axes, what formulas do I use
to figure out all 3 angles at the same time?
-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Timothy R  Cook
Subject: Re: Local coordinates?
Date: 5 Dec 2001 10:09:41
Message: <3C0E382C.4F0DDCB7@scifi-fantasy.com>
"Timothy R. Cook" wrote:
> I am trying to make it intersect points
>      A [-32.000   0.000  76.000]
>      B [-88.000  16.000 -40.000]
>      C [  0.000  26.000  24.000]

Correction, I'm trying to make it intersect points
      A [-32.000  76.000    0.000]
      B [-88.000 -40.000   16.000]
      C [  0.000  24.000   26.000]
-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Warp
Subject: Re: Local coordinates?
Date: 5 Dec 2001 10:31:18
Message: <3c0e3dc6@news.povray.org>
translate -LocalCoord
rotate whatever
translate LocalCoord

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Timothy R  Cook
Subject: Re: Local coordinates?
Date: 5 Dec 2001 10:47:08
Message: <3C0E40F5.338CC280@scifi-fantasy.com>
Warp wrote:
> translate -LocalCoord
> rotate whatever
> translate LocalCoord

That's somewhat less than useful...it places the axes
somewhere in nevernever land, which doesn't help me
because I don't know the angles I need to rotate it,
so I'd have to rotate, move, rotate, move, etc.

Basically what I'm doing is modelling a VRML file
with CSGs that intersect the points, chopping away
at a cube.
-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Ron Parker
Subject: Re: Local coordinates?
Date: 5 Dec 2001 10:52:54
Message: <slrna0sgmo.f1g.ron.parker@fwi.com>
On Wed, 05 Dec 2001 10:05:06 -0500, Timothy R. Cook wrote:
> Is there a way to rotate an object around its local coordinate
> axes?  What I have is this:

In general, you do local transformations before global ones.  If it's
too late for that, you need to transform by the inverse of whatever the
global one was, then do the local, then transform by the global one again.

I once wrote some macros to handle local and global transforms in a
somewhat intuitive way.  They didn't work in 3.1, due to a parser bug 
in the transform{} statement, but they should work in 3.5.  If you'd
like, I can dig them up; they're on this server somewhere.

-- 
#local R=<7084844682857967,0787982,826975826580>;#macro L(P)concat(#while(P)chr(
mod(P,100)),#local P=P/100;#end"")#end background{rgb 1}text{ttf L(R.x)L(R.y)0,0
translate<-.8,0,-1>}text{ttf L(R.x)L(R.z)0,0translate<-1.6,-.75,-1>}sphere{z/9e3
4/26/2001finish{reflection 1}}//ron.parker@povray.org My opinions, nobody else's


Post a reply to this message

From:
Subject: Re: Local coordinates?
Date: 5 Dec 2001 10:58:44
Message: <tkgs0usl8565tofgaarvngipqnlfp1pg33@4ax.com>
On Wed, 05 Dec 2001 10:05:06 -0500, "Timothy R. Cook"
<tim### [at] scifi-fantasycom> wrote:
> Is there a way to rotate an object around its local coordinate
> axes?

I'm not sure I understand but perhaps this could help. At first you can use
plane instead of box. You can calculate plane parameters from points A,B,C.
Normal of this plane is cross product of vectors BA and CA. Then you have to
translate this plane to point A. I hope it is correct and possible with Moray.
I've never used this modeler.

ABX
--
#declare _=function(a,b,x){((a^2)+(b^2))^.5-x}#default {pigment{color rgb 1}}
union{plane{y,-3}plane{-x,-3}finish{reflection 1 ambient 0}}isosurface{ //ABX
function{_(x-2,y,1)|_((x+y)*.7,z,.1)|_((x+y+2)*.7,z,.1)|_(x/2+y*.8+1.5,z,.1)}
contained_by{box{<0,-3,-.1>,<3,0,.1>}}translate z*15finish{ambient 1}}//POV35


Post a reply to this message

From: Ron Parker
Subject: Re: Local coordinates?
Date: 5 Dec 2001 11:05:40
Message: <slrna0shel.f6c.ron.parker@fwi.com>
On 5 Dec 2001 10:52:54 -0500, Ron Parker wrote:
> On Wed, 05 Dec 2001 10:05:06 -0500, Timothy R. Cook wrote:
>> Is there a way to rotate an object around its local coordinate
>> axes?  What I have is this:
> 
> In general, you do local transformations before global ones.  If it's
> too late for that, you need to transform by the inverse of whatever the
> global one was, then do the local, then transform by the global one again.
> 
> I once wrote some macros to handle local and global transforms in a
> somewhat intuitive way.  They didn't work in 3.1, due to a parser bug 
> in the transform{} statement, but they should work in 3.5.  If you'd
> like, I can dig them up; they're on this server somewhere.

Here they are.  But of course, if you're using Moray they won't be of any
use to you.

#macro trans_rotate( trans, rot, islocal )
  #declare trans=transform {
     #if (islocal) rotate rot #end
     transform{trans}
     #if (!islocal) rotate rot #end
  }
#end

#macro trans_scale( trans, scl, islocal )
  #declare trans=transform {
     #if (islocal) scale scl #end
     transform{trans}
     #if (!islocal) scale scl #end
  }
#end

#macro trans_translate( trans, tr, islocal )
  #declare trans=transform {
     #if (islocal) translate tr #end
     transform{trans}
     #if (!islocal) translate tr #end
  }
#end

#declare My_trans=transform{ scale 1 } // identity matrix
trans_rotate( My_trans, 45*y, no ) // global rotate
trans_translate( My_trans, x, yes ) // local translate

-- 
#macro R(P)z+_(P)_(P)_(P+1)_(P+1)+z#end#macro Q(C,T)bicubic_patch{type 1u_steps
6v_steps 6R(1)R(3)R(5)R(7)pigment{rgb z}}#end#macro _(Y)#local X=asc(substr(C,Y
,1))-65;<T+mod(X,4)div(X,4)9>-2#end#macro O(T)Q("ABEFUQWS",T)Q("WSXTLOJN",T)#
end O(0)O(3)Q("JNKLCGCD",0)light_source{x 1}// ron### [at] povrayorg


Post a reply to this message

From: Timothy R  Cook
Subject: Re: Local coordinates?
Date: 5 Dec 2001 11:57:10
Message: <3C0E515D.28AAEA87@scifi-fantasy.com>
Oy.  I have the list of vertices, might as well make a RAW of it.
Except...you can't CSG RAWs.  Urgh.
-- 
Tim Cook
http://empyrean.scifi-fantasy.com

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GFA dpu- s: a?-- C++(++++) U P? L E--- W++(+++)>$
N++ o? K- w(+) O? M-(--) V? PS+(+++) PE(--) Y(--)
PGP-(--) t* 5++>+++++ X+ R* tv+ b++(+++) DI
D++(---) G(++) e*>++ h+ !r--- !y--
------END GEEK CODE BLOCK------


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Local coordinates?
Date: 6 Dec 2001 18:59:39
Message: <3C1003DE.BE8FBDCE@hotmail.com>
"Timothy R. Cook" wrote:
> 
> Is there a way to rotate an object around its local coordinate
> axes?  What I have is this:
> 
> Box
> scale  [ 34.000  10.000  60.000]
> rotate [  5.000 -53.975   0.000]
> transl [-44.000  21.000  -8.000]
>   local coords
> scale  [  1.000   1.000   1.000]
> rotate [  0.000   0.000   0.000]
> transl [ -1.000   1.000   0.000]
> 
> I am trying to make it intersect points
>      A [-32.000   0.000  76.000]
>      B [-88.000  16.000 -40.000]
>      C [  0.000  26.000  24.000]
> to difference it from an object.  I have it rotated to where
> I want it XY, but when I try rotating it around its Z axis,
> it rotates around the WORLD axis, not its own, and the local
> coordinate rotation just shears the box at whatever angle,
> not at all what I want.
> 
> So, what do I do to get the effect I want?  If I need to
> rotate it on the real-world axes, what formulas do I use
> to figure out all 3 angles at the same time?


I saw this post at the news web-pages at the POV-
Ray server (messages digest) and then made a
script file in order to try to solve your problem.

Unfortunately I realized too late that this was a
moray-related question. =(

But I'll post the code anyway in case anyone is
interested.


Tor Olav


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

#version 3.5;

#include "colors.inc"

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// The camera equipment

camera {
  location <-50, -10, 300>
  look_at <0, 0, 0>
}

light_source {
  <-1, -1, 1>*1000
  color White
  shadowless
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Some useful macros

#macro AxisRotateMatrix(vAxis, Angle)

  #local Phi = radians(Angle);
  #local Cos = cos(Phi);
  #local Sin = sin(Phi);
  #local vL = vnormalize(vAxis);
  #local vM = vL*(1 - Cos);

  matrix <
    vM.x*vL.x +      Cos, vM.y*vL.x + vL.z*Sin, vM.z*vL.x - vL.y*Sin,
    vM.x*vL.y - vL.z*Sin, vM.y*vL.y +      Cos, vM.z*vL.y + vL.x*Sin,
    vM.x*vL.z + vL.y*Sin, vM.y*vL.z - vL.x*Sin, vM.z*vL.z +      Cos,
                       0,                    0,                    0
  >

#end // macro AxisRotateMatrix


#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;
  #local vA = v0.x*vW;
  #local vB = v0.y*vW;
  #local vC = v0.z*vW;

  matrix <
    vA.x + Dot,  vA.y + vU.z, vA.z - vU.y,
    vB.x - vU.z, vB.y + Dot,  vB.z + vU.x,
    vC.x + vU.y, vC.y - vU.x, vC.z + Dot,
    0,                0,                0
  >

#end // macro ReorientMatrix


#macro vTransform(v0, Transform)

  #local Fn = function { transform { Transform } }

  Fn(v0.x, v0.y, v0.z)

#end // macro vTransform

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Now work with the problem (as I understood it)

// Deifne a box
#declare InitialBox = box { -<2, 0.1, 1.5>, <2, 0.1, 1.5> }

// And it's centre
#local pCtr = <0, 0, 0>;

// Decide how to transform it in world coordinates
#declare WorldTrans =
transform {
  scale  <34.000, 10.000, 60.000>
  rotate <5.000, -53.975, 0.000>
  translate <-44.000,  21.000,  -8.000>
}

// DoItToIt
#declare OnceTransformedBox =
object {
  InitialBox
  transform { WorldTrans }
}

// Decide how to transform it locally
#declare LocalTrans =
transform {
  scale  <1, 1, 1>
  rotate <0, 0, 0>
  translate <-1, 1, 0>
}

// DoItToIt
#declare TwiceTransformedBox =
object {
  OnceTransformedBox
  transform { WorldTrans inverse }
  transform { LocalTrans }
  transform { WorldTrans }
}

// Uncomment to see it now:
//object { TwiceTransformedBox pigment { color White } }

// Calculate the complete transformation it has gone through
// until now:
#declare TotalTrans = transform { LocalTrans WorldTrans }

// Find it's new centre and which direction it's y-axis is pointing:
#declare pNewCtr =
vTransform(pCtr, transform { TotalTrans });

#declare vNewY =
vTransform(pCtr + y, transform { TotalTrans }) - pNewCtr;

// Now that we know it's new centre and y-axis we can forget all
// about the transformations it has gone through up til now.

// The next task is to make the transformed box "intersect" with
// these three points:

#declare pA = <-32,  76,  0>;
#declare pB = <-88, -40, 16>;
#declare pC = <  0,  24, 26>;

// Show the points
sphere { pA, 5 pigment { color Cyan*2 } }
sphere { pB, 5 pigment { color Magenta*2 } }
sphere { pC, 5 pigment { color Yellow*2 } }

// Find two non paralell vectors for the plane they lie within:
#declare vCA = pA - pC;
#declare vCB = pB - pC;

// Note that although vCA and vCB seems to be perpendicular,
// they are not. I.e.: vdot(vCA, vCB) != 0

// And a normal vector for that plane:
#declare vUp = vcross(vCA, vCB);

// Also find a point that lies in the middle of these
// three points:
#declare pMid = (pA + pB + pC)/3;


// Then calculate the complete transform needed to make the box
// "intersect" with the three spheres:
#declare IsecPtsTrans =
transform {
  translate -pNewCtr
  ReorientMatrix(vNewY, vUp)
//  AxisRotateMatrix(vUp, 45)
  translate pMid  
}
// If the box is to be rotated within the plane that the three
// spheres lie in, then uncomment the line above. 


// Transform it to it's final position and show it:
object {
  TwiceTransformedBox
  transform { IsecPtsTrans }
  pigment { color Yellow }
}
 
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

/*
// Uncomment this region if you want to see the new local axes
// for the box in its final state.

// Finding its new (now old) x and z axes in the same way as we
// found the y axis above:

#declare vNewX =
vTransform(pCtr + x, transform { TotalTrans }) - pNewCtr;

#declare vNewZ =
vTransform(pCtr + z, transform { TotalTrans }) - pNewCtr;

// Calculate were its final centre is:
#declare pFinalCtr =
vTransform(pNewCtr, transform { IsecPtsTrans });

// And the direction of its final local x, y, z axes:
#declare vFinalX =
vTransform(pNewCtr + vNewX, transform { IsecPtsTrans }) - pFinalCtr;

#declare vFinalY =
vTransform(pNewCtr + vNewY, transform { IsecPtsTrans }) - pFinalCtr;

#declare vFinalZ =
vTransform(pNewCtr + vNewZ, transform { IsecPtsTrans }) - pFinalCtr;

// Maybe we want to specify a length for the axes ?
//#declare vFinalX = 60*vnormalize(vFinalX);
//#declare vFinalY = 60*vnormalize(vFinalY);
//#declare vFinalZ = 60*vnormalize(vFinalZ);


// A simple macro to show an axis

#macro Axis(v0, pCenter, Radius, Colour)

  union {
    sphere { -v0, Radius }
    cylinder { -v0, v0, Radius }
    sphere {  v0, Radius }
    translate pCenter
    pigment { color Colour }
  }

#end // macro Axis

// Show them
Axis(vFinalX, pFinalCtr, 2, Red)
Axis(vFinalY, pFinalCtr, 2, Green)
Axis(vFinalZ, pFinalCtr, 2, Blue)
*/

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

// If we hadn't done all the world and local transformations to
// the box, then these few lines of code would have done something
// similar to it as the code above. (One of the sides of the box
// would even be aligned with two of the spheres.)


#declare vPlY = vnormalize(vUp);
#declare vPlZ = vnormalize(vcross(vCB, vPlY));
#declare vPlX = vcross(vPlY, vPlZ);

#declare OneSingleTrans =
transform {
  matrix <
    vPlX.x, vPlX.y, vPlX.z,
    vPlY.x, vPlY.y, vPlY.z,
    vPlZ.x, vPlZ.y, vPlZ.z,
         0,      0,      0
  >
}


// Uncomment to see the effect:
/*
object {
  InitialBox // box { -<2, 0.1, 1.5>, <2, 0.1, 1.5> }
  scale <34, 10, 60> // It's very small so scale it
  transform OneSingleTrans
//  AxisRotateMatrix(vPlY, 45)
  translate pMid
  pigment { color Orange + White }
}
*/


// Also have a look at this:
// (Lines up the edges along the spheres.)
/*
object {
  InitialBox // box { -<2, 0.1, 1.5>, <2, 0.1, 1.5> }
  scale <34, 10, 60>
  transform OneSingleTrans
  translate pC + 2*34*vPlX + 0.1*10*vPlY + 1.5*60*vPlZ
  pigment { color Orange + Yellow }
}
*/


// And this:
// (Same result as from the one above.)
/*
object {
  box { <0, 0, 0>, 2*<2, 0.1, 1.5> }
  scale <34, 10, 60>
  transform OneSingleTrans
  translate pC
  pigment { color Orange + Red }
}
*/

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

/*
// Finally:
// If vCA and vCB had been perpendicular to each other, this
// would have been a quite nice solution to the problem:
// (The box made from the code below is a little bit skewed.)

#declare vPlZ = vCA;
#declare vPlX = vCB;
#declare vPlY = 4*vnormalize(vcross(vCA, vCB));

object {
  box { <0, 0, 0>, <1, 1, 1> }
  matrix <
    vPlX.x, vPlX.y, vPlX.z,
    vPlY.x, vPlY.y, vPlY.z,
    vPlZ.x, vPlZ.y, vPlZ.z,
      pC.x,   pC.y,   pC.z
  >
  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.