finding angle with trigonometry: help!

   1812   2   1
User Avatar
Member
1010 posts
Joined: April 2017
Offline
Hi!

I wanted to make a patch of grass where all the grass blades faces away from the origin. All my points are on the X and Z axis (Y is always zero). Since I have my @P.x and @P.y, I though I could find the radian by using atan. Later, I could use that radian in a quaternion.

The results works only in the -X but not in the +X. Here's my vex:


vector up = set(0,1,0);
float radians = atan(@P.x/@P.z);

@orient = quaternion(radians, up);


I don't remember much of trigonometry so I probably used it the wrong way…

Any help is appreciated!

-Olivier

Attachments:
Trigono_find_angle.jpg (141.0 KB)

User Avatar
Member
1010 posts
Joined: April 2017
Offline
Ahh!! FIXED!

Instead of using atan function, I used atan2 function.


vector up = set(0,1,0);
float radians = atan2(@P.x, @P.z);

@orient = quaternion(radians, up);



yeah! (*self high-five)

-Olivier
User Avatar
Member
80 posts
Joined: June 2013
Offline
Could you use vectors? Object Z+ points along @N on copy eliminating need for @orient. Lets the ‘origin’ be an arbitrary location as well.

v@N = @P - set(0.0,0.0,0.0);
Edited by Rebus B - Sept. 18, 2018 16:14:02
  • Quick Links