POV-Ray : Newsgroups : povray.newusers : Full 360 with VAngleD : Re: Full 360 with VAngleD Server Time
29 Nov 2021 22:44:52 EST (-0500)
  Re: Full 360 with VAngleD  
From: Tor Olav Kristensen
Date: 10 Oct 2019 14:45:01
Message: <web.5d9f7b4becd82d81ed4479290@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Trying to use VAngleD with a 2D vector and x only gives me 0 to 180 deg.
> Hoping that someone can provide a simple way to get a 0 to 360 result.
>
> Perhaps update the distro to perform this (as a new macro?) or at least comment
> the existing macro to reflect this, and maybe add the crucial code in the
> comment as well)
>
> Have to head out to work, so....

Try this:


#version 3.7;


// Calculate the angle from vA to vB in 2D

#macro Angle2D(vA, vB)

    #local AngleA = atan2(vA.v, vA.u);
    #local AngleB = atan2(vB.v, vB.u);
    #local dAngle = AngleB - AngleA;

    degrees(dAngle)  // For result from -180 to +180 degrees
    // degrees(mod(dAngle + 2*pi, 2*pi))  // For result from 0 to +360 degrees

#end // macro Angle2D


#declare v0 = <-2, 3>;
#declare v1 = <3, 2>;


#debug "\n"
#debug "\n"
#debug str(Angle2D(v0, v1), 0, 12)

#debug "\n"
#debug "\n"

#error "To stop render window from opening"


NB! I have only tested this lightly.

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

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