-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[raymath] Vector2LineAngle() may be giving wrong results #3387
Comments
Yep, Ray, I think it will be better to make sure there is an explanation on how raylib(raymath) defines its axis grid, so we can better argue about what is wrong and what is right. I had seen that a lot of has been opened about the angles function, so i think adding a conversion on the outputted angle from raymath's functions would be a great way to remove any confusion in the future. p.s. sorry for the broken English. |
@Murlocohol @sDos280 Yes, there is some problem with that function, you can check Help on making it working as expected is welcome. |
There is indeed an inconsistency between Vector2Angle and Vector2LineAngle. |
Well, that's the problem. That why we need concrete conversation for angle output/measurement. In my interpretation of raymath, raymath is just a mathematical tool (based on the regular angle measurement we all know and love), not one that is specifically for raylib uses, but for general purpose... |
@raysan5 what your opinion on the way angels should be measured? (Raylib space) x+ to y+ positive angle, or (raylib space) x+ to y+ positive angle (like in the regular axis grid)? |
Just put up a pull request for this #3394 that fixes raymath.h and the corresponding example. I went with clockwise angles just so raylib is consistent for now. If I can throw my hat into the ring, I would vote for counter-clockwise angles, simply because I think that is what most people learn in school (and come to expect.) Here is a gif of the updated example working, I also added the ability to move v1 around because that's fun and stuff. Again, apologies if I mess anything up, this is my first pull request. |
The problem is in Vector2Angle, not Vector2LineAngle. I would advise against using rendering in raylib to determine the correctness of these functions. Intuition about angles is thrown off by the fact that Y+ is down in raylib. If you really want to, you can use a custom matrix that makes Y+ up and test it that way. |
First of all, You can't massed things up, in the worst case your PR wouldn't be merged, so don't worry 😉. I agree with you, angle measurement should be (positive for) counter clockwise, but I see people disagreeing with us... |
"The coordinate system in raylib is a 2D This is a standard graphics arrangement for computer displays. (Also for ASCII art on line printers.) It has the advantage of placing no inherent constraint on the horizontal or vertical capacity of the display. All of the essential stuff from So, when you say clockwise/counter-clockwise, are you talking about in the coordinate system (standard textbook Cartesian orientation) or as seen by the user (computer graphic orientation)? If you mean counter-clockwise in the viewer's frame of reference, that will be clockwise in the Cartesian orientation. At some point you have to cope with window height to place and animate the images as seen by the viewer. Since raylib is predisposed to graphic orientation, I trust it is employed consistently in the raylib functions where it matters. The application can adjust and scale on that basis. Transformations for orientation and axis scale can also be done, but it can be expensive if there is much of that. I suspect that text functions presume graphical orientation, text appearing right-side-up by default. It would be useful for raylib documentation to be emphatic about this. It's not on the cheatsheet. In the wiki perhaps? |
@veins1 @sDos280
That is exactly what I meant and I realized my error all too late, unfortunately. |
@Murlocohol Thank you very much for reviewing the issue and the example! Proposed solution looks good to me! |
Ahh! Sorry to reopen this, I was in the middle of fixing the edit as pointed out by @veins1 and @orcmid. I posted a new pull that should be the correct version now #3396. Sorry I wasn't faster on the draw or I could've avoided this. I made another example that shows the newly implemented correct behavior: |
Nevermind, I don't know how to reopen this. Hopefully @raysan5 will see this. |
@Murlocohol Mmmh... I tried the PR I merged and it seemed to work as expected, what was the problem? |
@Murlocohol Now it seems to be completely broken, please, could you sync to latest master branch and review it? |
@Murlocohol Nevermind, I just reviewed it. |
@raysan5 Thank you! And sorry again I'm not completely used to using git so I think I messed up with the commits on my end. |
This is something always worth learning to keep in mind. Don't be embarrassed. We can all slip up on this one. And learn from each other. |
As far as I am aware I have done the following:
Issue description
Vector2Angle and Vector2LineAngle give results of different signedness. This might be intended behavior but I wasn't sure.
After looking at some other functions that use angles (Vector2Rotate() and DrawCircleSector()) it seems raylib has a clockwise bias for angles, so I am inclined to think that Vector2Angle() has the correct result of the two.
Issue Screenshot
Solution
In raymath.h, Simply changing "atan2f" in Vector2LineAngle() to "-atan2f" should fix the issue.
Code Example
You can test the behavior with the following program:
Apologies if this is painfully bad, it's my first time submitting an issue.
The text was updated successfully, but these errors were encountered: