









 
 




 
 


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)


 
 




 
 


Am 20170529 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


 
 




 
 


Am 20170529 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 LookatCamera 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_atcamera),
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)


 
 




 
 


dick balaska <dic### [at] buckosoftcom> wrote:
> Am 20170529 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 LookatCamera 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


 
 




 
 


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(LACam), LA.x)) and degrees(atan2(Vlength(LACam), LA.y))
or expanded:
degrees( atan2 ( sqrt( ((LA.xCam.x)^2)+((LA.yCam.y)^2)+((LA.zCam.z)^2) ),
LA.x ))
degrees( atan2 ( sqrt( ((LA.xCam.x)^2)+((LA.yCam.y)^2)+((LA.zCam.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


 
 




 
 


On 31/05/2017 07:06, dick balaska wrote:
> Am 20170529 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 LookatCamera 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_atcamera),
> 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)


 
 




 
 


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


 
 




 
 


Am 20170531 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 nonsolid, nonspherical shapes.
Thanks!

dik
Post a reply to this message


 
 




 
 


Am 20170531 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 nonarticulated 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


 
 




 
 


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 nonarticulated 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, eyeandthumb, protractor, or backestimating 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.yCam.y, LookAt.xCam.x) )
Post a reply to this message


 
 




 

