Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
Keep angle between 1 and 180 degrees

I have the following which returns the rotation in degrees of an object, lensParentRight, through 360.

This is in Adobe Animate HTML5 Canvas (create.js/easel.js would apply). cylinderAngle is just an offset.

var cylinderAngleText = Math.abs((Math.round(((root.lensParentRight.rotation + cylinderAngle) * 100) / 100))) + "\u00B0"; 

I want to keep the angle returned between 1 and 180.

How would this be done in JavaScript?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could always limit your variable values using mod "%" at end of your mathematical expression. ((exp)%180) in your case. I hope that helps.

about 4 years ago · Juan Pablo Isaza Report

0

To add 2 numbers and constrain the value to lie within a specified range requires that you implement overflow on the results of the addition. Something like this:

function add_and_constrain_to_range( a, b, lo, hi ) {
  const range = hi - lo ;
  const sum   = a  + b  ;
  const result = lo + ( sum % range ) ;
  return result;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!