POV-Ray : Newsgroups : povray.off-topic : Vector math question.. Server Time
7 Sep 2024 05:11:53 EDT (-0400)
  Vector math question.. (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Patrick Elliott
Subject: Vector math question..
Date: 23 Aug 2008 18:15:31
Message: <48b08c03$1@news.povray.org>
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);

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

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.

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.

-- 
void main () {

     if version = "Vista" {
       call slow_by_half();
       call DRM_everything();
     }
     call functional_code();
   }
   else
     call crash_windows();
}

<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models, 
3D Content, and 3D Software at DAZ3D!</A>


Post a reply to this message

From: John VanSickle
Subject: Re: Vector math question..
Date: 23 Aug 2008 21:53:47
Message: <48b0bf2b@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.

Take the dot product of the pushing force vector (not normalized) and 
the vector for the facing object (normalized), and check the sign.  If 
the sign is negative (force and facing opposed to some degree), then 
multiply the dot product by the normalized value of the pushing force, 
and then subtract this from the pushing force, to yield a vector that is 
perpendicular to the pushing force.

Regards,
John


Post a reply to this message

From: Patrick Elliott
Subject: Re: Vector math question..
Date: 23 Aug 2008 23:56:08
Message: <48b0dbd8$1@news.povray.org>
John VanSickle wrote:
> 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.
> 
> Take the dot product of the pushing force vector (not normalized) and 
> the vector for the facing object (normalized), and check the sign.  If 
> the sign is negative (force and facing opposed to some degree), then 
> multiply the dot product by the normalized value of the pushing force, 
> and then subtract this from the pushing force, to yield a vector that is 
> perpendicular to the pushing force.
> 
> Regards,
> John

Ok, so umm, basically, like:

objnorm = VecNorm(GetRot);
windnorm = VecNorm(wind);
xdot = Wind.x * objface.x;
ydot = Wind.y * objface.y;
if xdot < 0
   Wind.x -= xdot * windnorm.x;
if ydot < 0
   Wind.y -= ydot * windnorm.y;
SetForce (Wind);

Now, I think this just reverses the force, right, so if I wanted to make 
it got the reverse way, I would double the result of the dot product * 
the force, so it move the reverse direction, not just negates it?

-- 
void main () {

     if version = "Vista" {
       call slow_by_half();
       call DRM_everything();
     }
     call functional_code();
   }
   else
     call crash_windows();
}

<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models, 
3D Content, and 3D Software at DAZ3D!</A>


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Vector math question..
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

From: Tor Olav Kristensen
Subject: Re: Vector math question..
Date: 24 Aug 2008 07:49:59
Message: <48b14ae7$1@news.povray.org>
Tor Olav Kristensen wrote:
> Patrick Elliott wrote:
...
>> 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:
...

I did not read the above thoroughly enough.

But unfortunately I do not have time right now to show you how
to do this. Maybe later.

Btw.: I did not notice that John VanSickle has already replied.
Maybe his answer helped you.

-- 
Tor Olav
http://subcube.com


Post a reply to this message

From: Patrick Elliott
Subject: Re: Vector math question..
Date: 24 Aug 2008 13:09:24
Message: <48b195c4@news.povray.org>
Tor Olav Kristensen wrote:
> Tor Olav Kristensen wrote:
>> Patrick Elliott wrote:
> ...
>>> 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:
> ...
> 
> I did not read the above thoroughly enough.
> 
> But unfortunately I do not have time right now to show you how
> to do this. Maybe later.
> 
> Btw.: I did not notice that John VanSickle has already replied.
> Maybe his answer helped you.
> 

Yes, you more or less confirm what he said, sort of. Though, I am still 
waiting for a confirmation from him that my pseudocode is right. There 
is no "vdot" function available in what I am working with, since its not 
POVRay, so I have to do some calculations manually. :(

-- 
void main () {

     if version = "Vista" {
       call slow_by_half();
       call DRM_everything();
     }
     call functional_code();
   }
   else
     call crash_windows();
}

<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models, 
3D Content, and 3D Software at DAZ3D!</A>


Post a reply to this message

From: Warp
Subject: Re: Vector math question..
Date: 24 Aug 2008 13:44:24
Message: <48b19df7@news.povray.org>
Patrick Elliott <sel### [at] npgcablecom> wrote:
> There 
> is no "vdot" function available in what I am working with, since its not 
> POVRay, so I have to do some calculations manually. :(

  The dot product of vectors is very trivial to calculate.

http://en.wikipedia.org/wiki/Dot_product

-- 
                                                          - Warp


Post a reply to this message

From: Patrick Elliott
Subject: Re: Vector math question..
Date: 24 Aug 2008 21:36:46
Message: <48b20cae$1@news.povray.org>
Warp wrote:
> Patrick Elliott <sel### [at] npgcablecom> wrote:
>> There 
>> is no "vdot" function available in what I am working with, since its not 
>> POVRay, so I have to do some calculations manually. :(
> 
>   The dot product of vectors is very trivial to calculate.
> 
> http://en.wikipedia.org/wiki/Dot_product
> 
Uh, wait.. Thought dot product in this case was the equivalent of matrix 
multiplication, that page implies that the vector results in a single 
value, not another vector... So, what I posted in my second reply to 
John was wrong?


-- 
void main () {

     if version = "Vista" {
       call slow_by_half();
       call DRM_everything();
     }
     call functional_code();
   }
   else
     call crash_windows();
}

<A HREF='http://www.daz3d.com/index.php?refid=16130551'>Get 3D Models, 
3D Content, and 3D Software at DAZ3D!</A>


Post a reply to this message

From: scott
Subject: Re: Vector math question..
Date: 25 Aug 2008 02:43:20
Message: <48b25488$1@news.povray.org>
This should work, it totally negates the direction of the wind force if 
hitting the "front" of the object.

objnorm = VecNorm(GetRot);
dot = wind.x * objnorm.x + wind.y * objnorm.y + + wind.z * objnorm.z;
if dot < 0
   wind = -wind;
SetForce (wind);

Or did you want only the component of the wind perpendicular to the wall to 
be negated?

if dot < 0
   Wind = wind - 2 * dot * objnorm;

Or did you want the component of wind perpendicular to the wall to be zero 
(as I think John explained)?

if dot < 0
   Wind = wind - dot * objnorm;


Post a reply to this message

From: Warp
Subject: Re: Vector math question..
Date: 25 Aug 2008 08:00:09
Message: <48b29ec8@news.povray.org>
Patrick Elliott <sel### [at] npgcablecom> wrote:
> Uh, wait.. Thought dot product in this case was the equivalent of matrix 
> multiplication, that page implies that the vector results in a single 
> value, not another vector... So, what I posted in my second reply to 
> John was wrong?

  You are probably confusing it with the cross-product.

-- 
                                                          - Warp


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

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