POV-Ray : Newsgroups : povray.advanced-users : Vector to Angle Server Time
28 Mar 2024 11:05:28 EDT (-0400)
  Vector to Angle (Message 1 to 10 of 24)  
Goto Latest 10 Messages Next 10 Messages >>>
From: dick balaska
Subject: Vector to Angle
Date: 29 May 2017 15:42:25
Message: <592c79a1$1@news.povray.org>
I'm trying to master converting a vector to an angle in 3D with no luck 
(2D sure, I got that).
I tried two different formulas with varying degrees of not success.
In the code below, the secret to my success will be the VtoA macro.
The result should be, the Cyan sphere, whose position is generated from 
the VtoA macro, should be locked in the center of the screen behind the 
Red sphere, which is locked to the center of the screen, because it is 
look_at.  The current odd return from VtoA is the closest I can get. 
This works good if I move from 0 in only one axis at a time.
Help?

-- 
dik


Post a reply to this message


Attachments:
Download 'test.inc.txt' (2 KB) Download 'animtest.ini.txt' (1 KB)

From: dick balaska
Subject: Re: Vector to Angle
Date: 29 May 2017 22:58:49
Message: <592cdfe9$1@news.povray.org>
Am 2017-05-29 15:42, also sprach dick balaska:
> I'm trying to master converting a vector to an angle in 3D
Of course I figured it out after finally asking:

// Convert this vector into its angle
#macro VtoA(V)
	#local _V=vnormalize(V);
	#local rZ=degrees(acos(_V.z));
	#local rY=0;
	#if (_V.y != 0)
		#local rY=degrees(atan2(_V.x,_V.y));
	#end
	#debug concat("rY/Z=", str(rY,0,2), ", ", str(rZ,0,2), "\n")
	<-rZ,0,-rY>
#end

-- 
dik


Post a reply to this message

From: dick balaska
Subject: Re: Vector to Angle
Date: 31 May 2017 02:06:43
Message: <592e5d73$1@news.povray.org>
Am 2017-05-29 15:42, also sprach dick balaska:
> I'm trying to master converting a vector to an angle in 3D with no luck 

Help, Math wizards, you're my only hope.

Ok. I'm stuck. I'm missing something.

My goal is to position an object in a fixed position on the screen, like 
carrying a flashlight. Or a gun, like in a video game.

So I need to calculate the angle of Lookat-Camera and act on that.

My primary macro works, but I'm missing something in determining the 
position of an object that is not exactly on the look_at.  I can't 
figure out if I need to subtract an angle or a vector or from whom.
For example, in this screen shot,
http://www.buckosoft.com/tteoac/video/testRenders/test001.png
the red ball is look_at,
the cyan ball is the angle correctly derived from (look_at-camera),
but the green ball is only correctly 1 unit horizontally to the right of 
the cyan ball for this angle <0,0,0>. Otherwise it spins incoherently 
(to me) around the cyan ball. Interestingly, it keeps the correct distance.
http://www.buckosoft.com/tteoac/video/testRenders/test.mp4

argh. I keep trying to work it out on paper, but I'm not feeling it.

-- 
dik


Post a reply to this message


Attachments:
Download 'test.inc.txt' (3 KB) Download 'animtest.ini.txt' (1 KB)

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 31 May 2017 07:55:01
Message: <web.592eae6e3905ed8fc437ac910@news.povray.org>
dick balaska <dic### [at] buckosoftcom> wrote:
> Am 2017-05-29 15:42, also sprach dick balaska:
> > I'm trying to master converting a vector to an angle in 3D with no luck
>
> Help, Math wizards, you're my only hope.
>
> Ok. I'm stuck. I'm missing something.
>
> My goal is to position an object in a fixed position on the screen, like
> carrying a flashlight. Or a gun, like in a video game.
>
> So I need to calculate the angle of Lookat-Camera and act on that.

I was looking through the docs, and there really is SO MUCH in the include files
and macros and functions, that I can hardly keep track of where I started once I
reach the end.

I'd say start by looking over the vector functions like VAngleD(),
VProject_Axis(), VProject_Plane()etc and see if you can maybe blindly plug in
vectors and get it to work.  There might be some scenes in the distribution that
have some good code snippets.
There might also be some good code snippets from things like sunpos.inc and
scenes like my watch animation that handle data like you're talking about.

> argh. I keep trying to work it out on paper, but I'm not feeling it.

I have been there SO many times.

I will try to draw it out on paper and see what I can tell you - unless someone
else jumps on this before then.


Post a reply to this message

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 31 May 2017 09:20:01
Message: <web.592ec2d03905ed8fc437ac910@news.povray.org>
OK, the way I see it is that you need to take the atan2 of your _distance_
between the 2 points and the x or y value of the look_at

The key is that you need to take into account the x AND y variation of your
vector when you calculate the x and y angles.   So use the whole vector length
in your atan2 function.

so, that would be something like

degrees(atan2(Vlength(LA-Cam), LA.x)) and degrees(atan2(Vlength(LA-Cam), LA.y))

or expanded:

degrees(  atan2 ( sqrt( ((LA.x-Cam.x)^2)+((LA.y-Cam.y)^2)+((LA.z-Cam.z)^2) ),
LA.x  ))

degrees(  atan2 ( sqrt( ((LA.x-Cam.x)^2)+((LA.y-Cam.y)^2)+((LA.z-Cam.z)^2) ),
LA.y  ))

(worked out in OpenOffice, so they _may_ some editing need (like the N^2
notation) )

Good luck, YMMV   :D


Post a reply to this message

From: scott
Subject: Re: Vector to Angle
Date: 31 May 2017 12:07:48
Message: <592eea54$1@news.povray.org>
On 31/05/2017 07:06, dick balaska wrote:
> Am 2017-05-29 15:42, also sprach dick balaska:
>> I'm trying to master converting a vector to an angle in 3D with no luck
>
> Help, Math wizards, you're my only hope.
>
> Ok. I'm stuck. I'm missing something.
>
> My goal is to position an object in a fixed position on the screen, like
> carrying a flashlight. Or a gun, like in a video game.
>
> So I need to calculate the angle of Lookat-Camera and act on that.
>
> My primary macro works, but I'm missing something in determining the
> position of an object that is not exactly on the look_at.  I can't
> figure out if I need to subtract an angle or a vector or from whom.
> For example, in this screen shot,
> http://www.buckosoft.com/tteoac/video/testRenders/test001.png
> the red ball is look_at,
> the cyan ball is the angle correctly derived from (look_at-camera),
> but the green ball is only correctly 1 unit horizontally to the right of
> the cyan ball for this angle <0,0,0>. Otherwise it spins incoherently
> (to me) around the cyan ball. Interestingly, it keeps the correct distance.
> http://www.buckosoft.com/tteoac/video/testRenders/test.mp4
>
> argh. I keep trying to work it out on paper, but I'm not feeling it.

Try the attached.


Post a reply to this message


Attachments:
Download 'test16.pov.txt' (3 KB)

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 31 May 2017 14:40:00
Message: <web.592f0daf3905ed8fc437ac910@news.povray.org>
Oh, a single rotational angle.
That makes sense.

I wasn't sure what he was after - it's hard to tell with something symmetric
like a sphere.

I'm guessing he wants to avoid:
http://www.mathwords.com/a/angle_depression.htm


Post a reply to this message

From: dick balaska
Subject: Re: Vector to Angle
Date: 31 May 2017 18:50:25
Message: <592f48b1$1@news.povray.org>
Am 2017-05-31 12:07, also sprach scott:
> On 31/05/2017 07:06, dick balaska wrote:
>> Help, Math wizards, you're my only hope.

> Try the attached.

Yeah baby! There's nothing like a copy/paste solution that I almost 
understand, but does exactly what I want. ;)
I can't wait to try it out on non-solid, non-spherical shapes.

Thanks!

-- 
dik


Post a reply to this message

From: dick balaska
Subject: Re: Vector to Angle
Date: 31 May 2017 19:00:36
Message: <592f4b14$1@news.povray.org>
Am 2017-05-31 07:52, also sprach Bald Eagle:

>> argh. I keep trying to work it out on paper, but I'm not feeling it.
> 
> I have been there SO many times.

One of my favorites was, my wife took a picture of me with my chin on 
the dining room table, playing with a Lego cow and a ruler.  Which, if 
you've seen my animation of the running non-articulated horses, you'll 
understand what I was trying to accomplish. ;)  Usually, it's just paper 
with random circles and triangles and lines and points.
She: "Do you understand any of that?"
Me: "Not really."

-- 
dik


Post a reply to this message

From: Bald Eagle
Subject: Re: Vector to Angle
Date: 1 Jun 2017 07:45:00
Message: <web.592ffd473905ed8fc437ac910@news.povray.org>
dick balaska <dic### [at] buckosoftcom> wrote:

> One of my favorites was, my wife took a picture of me with my chin on
> the dining room table, playing with a Lego cow and a ruler.  Which, if
> you've seen my animation of the running non-articulated horses, you'll
> understand what I was trying to accomplish. ;)

I can't tell you how many things I measure on a regular basis.
Rulers, tape measures, eye-and-thumb, protractor, or back-estimating from
photos....

Speaking of Legos - you ought to check out the Antikythera mechanism this guy
built entirely from Lego.   :O

> Usually, it's just paper
> with random circles and triangles and lines and points.

Yes.   I have piles and piles of paper with lines and circles and ellipses and
triangles, and then there are the ones where there's a rat's nest of curves and
5 pages of equations...

"WTF are you ***DOING***????!!!"
"Well, ..."
"No. never mind. OMG."


:D

BTW
I think if you just look at the rotation angle like a clock hand on the screen,
centered around your camera location, then all you're doing is calculating the
angle, given the x and y coordinates.

So that's just degrees ( atan2(LookAt.y-Cam.y, LookAt.x-Cam.x) )


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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