Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Trigonmetry?

I have a need to calculate the adjacent angle of a right angle triangle formed by a rectangle that is dictated by two sets of points. My plan is to use offset() on two elements to get absolute position co-ordinates, then determine the internal angle from the bottom left corner of this implied box so that i may rotate a thin rectangle element using css rotate.

Possible?

The only part i wouldn't know how to do right off the bat is the trigonometry syntax, and whether i need an external library for that.

*Note: I do understand that css rotate would rotate around the center of the element, so i would have to shift the rectangle over to compensate.

like image 999
C_K Avatar asked Feb 01 '26 11:02

C_K


1 Answers

The answer lies not in jQuery, but in JavaScript. JavaScript has a Math object which contains sin, cos, tan and other trigonometry and math-related things.

For example, to calculate the sine of 45 degrees:

var degrees=45;
var radians=degrees*Math.PI/180;
var sine=Math.sin(radians);
alert("sin("+degrees+" deg) is roughly equal to "+sine);
like image 146
icktoofay Avatar answered Feb 03 '26 06:02

icktoofay