A hard-written rotation constraint problem Resolution

Source: Internet
Author: User

Recently encountered a camera rotation constraint issue

Would have preferred to directly compare the Euler value solution, but the value of Eulerian angle is 0-360 of the interval, such as the current angle is 1, the range is 350-10, will be wrong. Need to make a circle-wide judgment.

Of course it can be converted into vectors to compare, but it's too expensive to calculate.

That means you need to write a clamp of the ring, like this one

Mathematics is not good, directly hard to write:

 Public Static floatAngleclamp (floatMinfloatMaxfloatvalue) {    if(Min > Max && (value < Max | | value >min)) {        returnvalue; }    if(Value > Min && value <max) {        returnvalue; } Value= value = =0? the: value; Min= min = =0? the: Min; Max= max = =0? the: Max; varA1 = the-Value +min; varB1 = Math.Abs (Min-value); varC1 = A1 < B1?a1:b1; varA2 = the-Value +Max; varb2 = Math.Abs (Max-value); varC2 = A2 < b2?a2:b2; if(C1 <C2) {        if(Value < min | | value >max) {            returnmin; }    }    Else    {        returnMax; }    return float. NaN;}
Angleclamp

Test Case:

There are a number of similar problems, but most of them can be directly written to the dead numerical judgment

A hard-written rotation constraint problem Resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.