POV-Ray : Newsgroups : povray.newusers : Help with: (planar) Angle between 2 vectors Server Time
23 Nov 2024 11:50:28 EST (-0500)
  Help with: (planar) Angle between 2 vectors (Message 1 to 7 of 7)  
From: Bald Eagle
Subject: Help with: (planar) Angle between 2 vectors
Date: 30 Jul 2014 15:45:00
Message: <web.53d94a479e261ad65e7df57c0@news.povray.org>
I'm just trying to return the angle between a fixed vector (pointing in the
-y*70 degrees direction) and the line of sight of the camera.
CL = Camera Location, LA = Look At point

I have a sort of crosshair that's centered at <45*8*Feet, 32*Feet, 55*8*Feet>,
which is why I have the translation in the vtransform.
I "project" the vectors onto the ground plane by just negating the y components
- multiplying that part of the dot product equation by zero.
(sorry for any of my non-mathematically correct terminology)
I get an answer of 9.2 degrees, but I was expecting zero, so I'm thinking I have
something off.

#declare CL = <45*8*Feet, 32*Feet, 55*8*Feet>;
#declare LA = vtransform (<0, 0, 10*8*Feet>, transform{rotate -y*70 translate
<45*8*Feet, 32*Feet, 55*8*Feet>});

// (CL.y * LA.y) defined to be planar - (0, 0)
#declare UdotV = (CL.x * LA.x) + (CL.y * LA.y) * 0 + (CL.z * LA.z);
#declare MagU = sqrt (pow (CL.x, 2) + pow (CL.y, 2) + pow (CL.z, 2) );
#declare MagV = sqrt (pow (LA.x, 2) + pow (LA.y, 2) + pow (LA.z, 2) );
#declare Angle = degrees (acos (UdotV / (MagU * MagV) ) );


Post a reply to this message

From: Bald Eagle
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 30 Jul 2014 16:35:00
Message: <web.53d955c7f138c3965e7df57c0@news.povray.org>
....aaaand Excel gives me 18 degrees from endpoints I got off of a diagram in
VISO for how I'm envisioning this working...
Grrrr....

THIS is why I didn't go into physics or physical chemistry.
OR engineering.
Lives would be at stake.   ;)


 x y z
u -2.6562 0 5.4688
v 0 0 7.3125


u dot v = 39.9906
Mag u         36.96317188
Mag v         53.47265625

cos theta =  0.020232844
radians          1.550562102
deg         88.84066433
minus 70 18.84066433


I'm gonna get more coffee, and then maybe buy a bike.  And THEN maybe I will
work on building my mathemagical powers....


Post a reply to this message

From: clipka
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 30 Jul 2014 20:01:53
Message: <53d98771$1@news.povray.org>
Am 30.07.2014 21:40, schrieb Bald Eagle:
> I'm just trying to return the angle between a fixed vector (pointing in the
> -y*70 degrees direction) and the line of sight of the camera.
> CL = Camera Location, LA = Look At point
>
> I have a sort of crosshair that's centered at <45*8*Feet, 32*Feet, 55*8*Feet>,
> which is why I have the translation in the vtransform.
> I "project" the vectors onto the ground plane by just negating the y components
> - multiplying that part of the dot product equation by zero.
> (sorry for any of my non-mathematically correct terminology)
> I get an answer of 9.2 degrees, but I was expecting zero, so I'm thinking I have
> something off.
>
> #declare CL = <45*8*Feet, 32*Feet, 55*8*Feet>;
> #declare LA = vtransform (<0, 0, 10*8*Feet>, transform{rotate -y*70 translate
> <45*8*Feet, 32*Feet, 55*8*Feet>});
>
> // (CL.y * LA.y) defined to be planar - (0, 0)
> #declare UdotV = (CL.x * LA.x) + (CL.y * LA.y) * 0 + (CL.z * LA.z);
> #declare MagU = sqrt (pow (CL.x, 2) + pow (CL.y, 2) + pow (CL.z, 2) );
> #declare MagV = sqrt (pow (LA.x, 2) + pow (LA.y, 2) + pow (LA.z, 2) );
> #declare Angle = degrees (acos (UdotV / (MagU * MagV) ) );

For ease of understanding and less possibilities to goof up, try using:

#declare U = vnormalize(CL*<1,0,1>);
#declare V = vnormalize(LA*<1,0,1>);
#declare Cos = dot(U,V);
#declare Angle = degrees(acos(Cos));


Post a reply to this message

From: Bald Eagle
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 30 Jul 2014 23:00:01
Message: <web.53d9b01af138c3965e7df57c0@news.povray.org>
> For ease of understanding and less possibilities to goof up, try using:
>
> #declare U = vnormalize(CL*<1,0,1>);
> #declare V = vnormalize(LA*<1,0,1>);
> #declare Cos = dot(U,V);
> #declare Angle = degrees(acos(Cos));

Right, I figured that there must be some of those black-box operations
somewhere, but I have a thing about seeing the "guts" of the math taking place.
(BTW, it's vdot(U,V) in case someone tries to follow this thread.)

I now get 7.9 degrees.

Then I figured, maybe there's a few more vector tricks that POV-Ray can do:

#declare Angle = VAngleD(VProject_Plane (CL, y),VProject_Plane (LA, y));

Still yields 7.9

So, follow me here:
#declare CL = <45*8*Feet, 32*Feet, 55*8*Feet>;
this I guess is the "tail" of the vector.

Then I take a vector pointing "forward" in the positive z direction.
I rotate it -70 degrees around the y-axis / origin.
I then translate that vector so that ITS "tail" is at the same place (with
regard to x and z) as the camera vector.

#declare LA = vtransform (<0, 0, 10*8*Feet>, transform{rotate -y*70 translate
<45*8*Feet, 32*Feet, 55*8*Feet>});

And I think I just gave myself the nudge I needed.  Those vectors aren't where
and pointing where I thought they were.  Those are the heads of the vectors, and
the tails are at the origin, aren't they?

I'd need to .... create a true line-segment as my "vector" (LA-CL), and NOT
translate the -70 degree reference vector away from the origin, wouldn't I?

[Everyone wait while I switch windows...]

Wicked awesome.
LA is now a true look_at value:  <45*8*Feet, 32*Feet, 65*8*Feet>
pointing in the +z direction, and the same x value.


#declare CL2 = (LA-CL);
#declare LA2 = vtransform (<0, 0, 10*8*Feet>, transform{rotate -y*70 });
#declare Angle = VAngleD(VProject_Plane (CL2, y),VProject_Plane (LA2, y));

And THAT spits out an angle of +70 degrees, which is correct.

Summary:  the confusion was predominately with the definition of a "vector" -
which I think was a problem about a year ago.
Thankfully, I have disabused my mind of the misunderstanding.
This time.
For now.

:O


Post a reply to this message

From: Thomas de Groot
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 31 Jul 2014 03:08:10
Message: <53d9eb5a$1@news.povray.org>
On 31-7-2014 4:55, Bald Eagle wrote:
> Thankfully, I have disabused my mind of the misunderstanding.
> This time.
> For now.

LOL.
Why do I find that so familiar? ;-)

Thomas


Post a reply to this message

From: Bald Eagle
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 31 Jul 2014 10:00:01
Message: <web.53da4b1ff138c3965e7df57c0@news.povray.org>
I posted a diagram for posterity.  :)
I'm sure I have a lot more POV-Ray "homework" to do in the future.

http://news.povray.org/povray.binaries.images/thread/<web.53da40ce3a9a62465e7df57c0%40news.povray.org>/


Post a reply to this message

From: Bald Eagle
Subject: Re: Help with: (planar) Angle between 2 vectors
Date: 31 Jul 2014 10:10:00
Message: <web.53da4dcdf138c3965e7df57c0@news.povray.org>
No matter what I'm doing, I always seem to wind up somewhere on FL's website:

http://www.f-lohmueller.de/pov_tut/trans/trans_800e.htm


Post a reply to this message

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