POV-Ray : Newsgroups : povray.general : Math Question Server Time
1 Nov 2024 01:23:41 EDT (-0400)
  Math Question (Message 1 to 10 of 10)  
From: Robert J Becraft
Subject: Math Question
Date: 2 Dec 1999 07:54:38
Message: <38466c0e@news.povray.org>
I'm posting this because I'm sure it is a simple trig thing and that was too
many years ago for me to remember it.

I have an object... let us assume it is a picture for simplicity....


camera ----->      picture

In this scenario, the picture is perpendicular to the viewing angle of the
camera.  What I want is the formula that will tell me how much to rotate the
picture to keep the picture perpendicular when I MOVE the camera.

For example, if the camera is at <0,0,0> and the picture is at <10,0,0>  and
then I move the camera to <0,0,5>, how much do I need to rotate the picture
to get it back to a 90 degree angle respective to the camera?   X,Z
coordinates are fine, I don't need any 3-D solutions to this problem.

Regards,
Robert J Becraft
aka cas### [at] aolcom


Post a reply to this message

From: Mark Gordon
Subject: Re: Math Question
Date: 2 Dec 1999 08:17:10
Message: <3846713A.E1320F73@mailbag.com>
Robert J Becraft wrote:
> 
> I'm posting this because I'm sure it is a simple trig thing and that was too
> many years ago for me to remember it.
> 
> I have an object... let us assume it is a picture for simplicity....
> 
> camera ----->      picture
> 
> In this scenario, the picture is perpendicular to the viewing angle of the
> camera.  What I want is the formula that will tell me how much to rotate the
> picture to keep the picture perpendicular when I MOVE the camera.
> 
> For example, if the camera is at <0,0,0> and the picture is at <10,0,0>  and
> then I move the camera to <0,0,5>, how much do I need to rotate the picture
> to get it back to a 90 degree angle respective to the camera?   X,Z
> coordinates are fine, I don't need any 3-D solutions to this problem.
> 
> Regards,
> Robert J Becraft
> aka cas### [at] aolcom

The inverse tangent of (5/10): 26.565051 degrees, about the y-axis. <0,
26.565051, 0>.  Unless I'm misreading the problem.

-Mark Gordon


Post a reply to this message

From: Robert J Becraft
Subject: Re: Math Question
Date: 2 Dec 1999 09:16:12
Message: <38467f2c@news.povray.org>
And the formula is???????????   The sample was for clearification... I need
the general formula that would be used to solve this problem.



>>The inverse tangent of (5/10): 26.565051 degrees, about the y-axis. <0,
>>26.565051, 0>.  Unless I'm misreading the problem.
>>
>>-Mark Gordon


Post a reply to this message

From: Josh English
Subject: Re: Math Question
Date: 2 Dec 1999 11:00:42
Message: <384697A8.B8EA05BB@spiritone.com>
There is a simple matrix tranformation you can use to orient everytthing. It
goes like this:

#declare Cam_Loc = wherever the camera is
#declare Obj_Loc = whereve the object

#macro Orient_Z(v1,v2)
  #local nz = vnormalize(v2 - v1);
  #local nx = vnormalize(vcross(nz,y));
  #local ny = vcross(nz,nx);
  matrix <nx.x,nx.y,nx.z,
          ny.x,ny.y,ny.z,
          nz.x,nz.y,nz.z,
          v1.x,v1.y,v1.z>
#end

box { <0,0,0> <1,1,0.01>
          pigment { image map details go here *** }
          transalate <-0.5,-0.5,0>
          scale appropriately
          Orient_Z(Obj_Loc, Cam_Loc)
         }

This version of the orient macro assumes something is designed along the Z
axis.

As far as the trig goes, it can be messy. Assume the camera stays at <0,0,0>
and the painting is at <10,0,0>, and limit it's movement only by translating it
along z, such as your example, then you have to remember that rotating an
object not located at the origin will move it as well as rotating it. Here I
will assume the painting setup as above, without the Orient_Z macro.

you have point p at <x,0,z> which is the final position of the painting.
 rotate arctan(p.z,p.x)*y
 translate p

Okay, simple, but if you want to move the painting in 3d space, use the Orient
macro, it's safer


Robert J Becraft wrote:

> I'm posting this because I'm sure it is a simple trig thing and that was too
> many years ago for me to remember it.
>
> I have an object... let us assume it is a picture for simplicity....
>
> camera ----->      picture
>
> In this scenario, the picture is perpendicular to the viewing angle of the
> camera.  What I want is the formula that will tell me how much to rotate the
> picture to keep the picture perpendicular when I MOVE the camera.
>
> For example, if the camera is at <0,0,0> and the picture is at <10,0,0>  and
> then I move the camera to <0,0,5>, how much do I need to rotate the picture
> to get it back to a 90 degree angle respective to the camera?   X,Z
> coordinates are fine, I don't need any 3-D solutions to this problem.
>
> Regards,
> Robert J Becraft
> aka cas### [at] aolcom

--

Josh English
eng### [at] spiritonecom
ICQ: 1946299
"Stress is when you wake up screaming and realize you haven't fallen asleep
yet."


Post a reply to this message

From: mr art
Subject: Re: Math Question
Date: 2 Dec 1999 11:22:38
Message: <38469CB9.D481A3FA@gci.net>
I had a simular problem with eyes and looking
at one spot. this is a solution.
given	P1,P2 are location vectors
	angle functions return radian values
	degrees() accepts radians and returns degrees
 
Use the function vnormalize(P2-P1) to return a vector of
	unit lingth that points from P1 to P2.
Use -degrees(asin(z componant)) and  degrees(asin(y componant)) 
	to return the amount of degrees that the object must be
	rotated while at P2 to face P1.
This assumes that the object is "facing" in the -x direction.

I have used a macro to keep the intent of the code clear.
I hope this helps. It gave me good results in making a
mannequin look at the camera.

#macro v_lookat(P1,P2)
	#local Norm=(vnormalize(P2-P1));
	<0,-degrees(asin(Norm.z)),degrees(asin(Norm.y))>
#end

#declare CameraPosition <-35,67,-16>;
#declare PicturePosition <2,-1,3>;
object	{
	Picture 
	rotate v_lookat( CameraPosition , PicturePosition )
	translate PicturePosition
	}


Post a reply to this message

From: Nieminen Juha
Subject: Re: Math Question
Date: 2 Dec 1999 11:27:02
Message: <38469dd6@news.povray.org>
The matrix page helps here also:
http://users.erols.com/vansickl/matrix.htm

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Rico
Subject: Re: Math Question
Date: 2 Dec 1999 11:39:50
Message: <3846A099.BBDC99D5@hotmail.com>
Hi Robert,

I used this kind of stuff few months ago to place eyes looking at the
viewer
(the camera location).
Just let let few seconds to find this in my hard drive. hem... hem....
hem....
ok, I get it !
Instead of a copy/paste piece of scene, I give you a small complete one,
totally FREE of charges. Lucky guy !! It's in the p.b.s-f group.
And for the same price, I gave you my prism eyes.
It was something I was working on for the Horror round, but I didn't
managed to finish the scene before the end of the competition.
You can change camera position and camera look_at to be sure that the
eyes follow the camera.

A+
Rico.


Post a reply to this message

From: Chris Colefax
Subject: Re: Math Question
Date: 2 Dec 1999 18:40:13
Message: <3847035d@news.povray.org>
Robert J Becraft <cas### [at] aolcom> wrote:
> I'm posting this because I'm sure it is a simple trig thing and that
was too
> many years ago for me to remember it.
>
> I have an object... let us assume it is a picture for simplicity....
> In this scenario, the picture is perpendicular to the viewing angle of
the
> camera.  What I want is the formula that will tell me how much to
rotate the
> picture to keep the picture perpendicular when I MOVE the camera.
>
> For example, if the camera is at <0,0,0> and the picture is at
<10,0,0>  and
> then I move the camera to <0,0,5>, how much do I need to rotate the
picture
> to get it back to a 90 degree angle respective to the camera?   X,Z
> coordinates are fine, I don't need any 3-D solutions to this problem.

If you are looking for a more general purpose solution to this problem,
you could try a custom lens effect using the Lens Effects include file
(http://www.geocities.com/~ccolefax).  This will allow you to position
an object (such as an image-mapped disc/polygon) perpendicular to the
camera, given the camera location and look_at, and the object position.
Further to that, you can create the effect as part of the scene (so it
is centred where you declare the object to be) or as an overlay (so it
appears to be centred where you declare the object to be, but actually
overlays the rest of the scene).  And you don't have to worry about any
of the math!


Post a reply to this message

From: David Vincent-Jones
Subject: Re: Math Question
Date: 3 Dec 1999 00:20:50
Message: <38475332@news.povray.org>
I tried to use this approach but unfortunately I need a more generalized
solution.
All I need.. is the angle (direction) between 2 vector locations..
but I need to ensure that it works in any and all quadrants.
My objects can always be rotated at origin prior to any move.
Surely there must be an easy solution sitting somewhere.
mr.art <mr.### [at] gcinet> wrote in message news:38469CB9.D481A3FA@gci.net...
> I had a simular problem with eyes and looking
> at one spot. this is a solution.
> given P1,P2 are location vectors
> angle functions return radian values
> degrees() accepts radians and returns degrees
>
> Use the function vnormalize(P2-P1) to return a vector of
> unit lingth that points from P1 to P2.
> Use -degrees(asin(z componant)) and  degrees(asin(y componant))
> to return the amount of degrees that the object must be
> rotated while at P2 to face P1.
> This assumes that the object is "facing" in the -x direction.
>
> I have used a macro to keep the intent of the code clear.
> I hope this helps. It gave me good results in making a
> mannequin look at the camera.
>
> #macro v_lookat(P1,P2)
> #local Norm=(vnormalize(P2-P1));
> <0,-degrees(asin(Norm.z)),degrees(asin(Norm.y))>
> #end
>
> #declare CameraPosition <-35,67,-16>;
> #declare PicturePosition <2,-1,3>;
> object {
> Picture
> rotate v_lookat( CameraPosition , PicturePosition )
> translate PicturePosition
> }


Post a reply to this message

From: Chris Colefax
Subject: Re: Math Question
Date: 4 Dec 1999 09:54:57
Message: <38492b41@news.povray.org>
David Vincent-Jones <geo### [at] galaxynetcom> wrote:
> I tried to use this approach but unfortunately I need a more
generalized
> solution.
> All I need.. is the angle (direction) between 2 vector locations..
> but I need to ensure that it works in any and all quadrants.
> My objects can always be rotated at origin prior to any move.
> Surely there must be an easy solution sitting somewhere.

If the vehicle is travelling on flat ground, and only rotating around
the y-axis, then the solution should indeed be fairly simple.  Let's say
you've declared the vehicle pointing towards the +z direction, so its
base (wheels or whatever) touches y=0 and it is centered at x=0 and z=0.
Given any direction we can calculate the rotation using the arc-tangent:

   object {Vehicle
      rotate y*degrees(atan2(Direction.x, Direction.z))
      translate Location}

The beauty of the atan2 function is that it works in all four quadrants,
and also works for the cases +z (0 degrees), +x (90 degrees), -z (180
degrees), and -x (-90 degrees).  However, it will not work when the
Direction vector is <0, 0, 0>, so if the vehicle is stationery during
the animation you will still need to supply a Direction.


Post a reply to this message

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