POV-Ray : Newsgroups : povray.newusers : Full 360 with VAngleD : Re: Full 360 with VAngleD Server Time23 Feb 2024 09:15:26 EST (-0500)
 Re: Full 360 with VAngleD
 From: Tor Olav Kristensen Date: 10 Oct 2019 14:45:01 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.5d9f7b4becd82d81ed4479290%40news.povray.org",
"headline": "Re: Full 360 with VAngleD",
"dateCreated": "2019-10-10T18:45:01+00:00",
"datePublished": "2019-10-10T18:45:01+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
"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
```