POV-Ray : Newsgroups : povray.off-topic : Vector math question.. : Re: Vector math question.. Server Time
7 Sep 2024 03:22:44 EDT (-0400)
  Re: Vector math question..  
From: Tor Olav Kristensen
Date: 24 Aug 2008 07:38:15
Message: <48b14827$1@news.povray.org>
Patrick Elliott wrote:
> Ok, first off, here is what I have to work with:
> 
> VecNorm = Normal for the vector.
> VecMag = Magnitude of the vector.
> Rot2Face = VecNorm(0,1,0) * VecMag.
> Rot2Left = VecNorm(1,0,0) * VecMag.
> Wind = returns a value of how "big" a force is blowing in x,y,z.
> GetRot = Current rotation of the object.
> SetForce = Set XForce, YForce and ZForce effecting the object.
> 
> Now, what I need to be able to do is take the objects rotation, figure 
> out which way its "facing", then negate any movement that pushes it the 
> opposite direction. This can be simple when in a fixed orientation, 
> facing the same direction as the winds X, or Y. I just check if the wind 
> vector is negative, I.e., blowing opposite the +X direction the object 
> is facing, and throw out, or reverse the value, so its now blowing +X, 
> instead of -X. This is however completely useless if/when trying to make 
> it move in an unknown orientation.
> 
> Hmm. To simplify, assume that we are dealing with a wall that is the 
> same "rotation" as the object itself, and that the object is a hanging 
> cloth. I need to be able to determine when/if the wind vector is 
> producing a push that is "towards" the wall, then invert it when that 
> happens, so that the hanging blows "Away" from the wall, but the left to 
> right movement needs to be the same as it would have been. So, in the 
> simplest terms, where the facing is +X:
> 
> hanging.rot = <0,0,0>
> if wind.x < 0
>   wind.x *= -1;
> SetForce(wind);

WARNING: Untested code below.

Your code in POV-Ray SDL:

#declare vCloth = <1, 0, 0>; // Cloth normal
#declare ClothRotation = <0, 0, 0>;
#if (vWind.x < 0)
   #declare vWind.x = -vWind.x;
#end // if
SetForce(vWind)


This would have been better:

#declare vCloth = <1, 0, 0>;
#declare ClothRotation = <0, 0, 0>;
#declare vCloth = vrotate(vCloth, ClothRotation);
#if (vdot(vWind, vCloth) < 0)
   #declare vWind = -vWind;
#end // if
SetForce(vWind)


> but how the hell do you do this if its like this?
> 
> hanging.rot = <10,30,0>
> if ??????
> 
> I am guessing that the VecNorm will come into play, but I have no damn 
> idea how. lol

Just put

#declare ClothRotation = <10, 30, 0>;

- into my suggestion above.


> Oh, and, just to make things more stupid, some bozo decided that euler 
> vector can't be multiplied in the system I am working with. You can 
> convert to a quaternion rotation, then do it, but not <1,2,3> * <3,2,1>. 
> :p You can however do vect1.x = vect2.x * vect3.x, multiplying each 
> value separately.

It's quite common that such vector multiplications are not defined, as
they are seldom used.


> Note, I am not sure if I need z or not. I am not currently using it, but 
> I suppose there may be cases where it could effect the result.

If you do successive transformations to the cloth, then code like this
can be used:

#include "transforms.inc"
#declare vCloth = <1, 0, 0>; // Cloth normal
#declare ClothRotation = <10, 30, 0>;
#declare ClothPosition = <2, -3, 5>;
#declare ClothTransformation =
   transform {
     rotate ClothRotation
     translate ClothPosition
   }
/*
#declare MoreClothRotation = <0, 45, 0>;
#declare ClothTransformation =
   transform {
     ClothTransformation
     rotate MoreClothRotation
   }
*/
#declare vCloth = vtransform(vCloth, ClothTransformation);
#if (vdot(vWind, vCloth) < 0)
   #declare vWind = -vWind;
#end // if
SetForce(vWind)

Be careful if the resulting transformation matrix of the transformation
is non-orthogonal, e.g. like it is when doing non-uniform scaling.

For such transformations, see:

   "Transforming normals - CGAFaq"
   http://www.cgafaq.info/wiki/Transforming_Normals

   "Normal Transforms"
   http://www.gignews.com/realtime020100.htm

-- 
Tor Olav
http://subcube.com


Post a reply to this message

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