POV-Ray : Newsgroups : povray.general : Math Question : Re: Math Question Server Time
10 Aug 2024 15:25:10 EDT (-0400)
  Re: Math Question  
From: Chris Colefax
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.