Jquery 三角函数?
我需要计算由两组点决定的矩形形成的直角三角形的邻角。我的计划是在两个元素上使用 offset() 来获取绝对位置坐标,然后确定该隐含框左下角的内角,以便我可以使用 css 旋转来旋转细长矩形元素。
可能的?
我唯一不知道如何立即执行的部分是三角函数语法,以及我是否需要外部库。
*注意:我确实知道 css 旋转会围绕元素的中心旋转,因此我必须将矩形移动以进行补偿。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案不在于 jQuery,而在于 JavaScript。 JavaScript 有一个
Math
对象,其中包含 < a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/sin" rel="noreferrer">sin
,cos
,tan
以及其他三角学和数学相关的东西。例如,计算 45 度的正弦:
The answer lies not in jQuery, but in JavaScript. JavaScript has a
Math
object which containssin
,cos
,tan
and other trigonometry and math-related things.For example, to calculate the sine of 45 degrees:
如果您计划使用旋转、创建圆、创建线条、绘制图表等进行一些真正的图形工作,请尝试使用 jquery/javascript 的 Raphael 图形库。
http://raphaeljs.com/reference.html
它提供了很多标准的功能,其中将帮助您更快、更有效地完成工作,而不是专注于旋转线的点等事情。
例如,Raphael 中有一个旋转功能,它允许您将任何对象顺时针旋转特定角度。
有平移、缩放等功能。
它还支持SVG图形。
If you are planning to do some real graphics work using things like rotate, create circles, create lines, draw charts etc, try the Raphael Graphics library for jquery/javascript.
http://raphaeljs.com/reference.html
It provides a lot of standard function do to stuff, which will help you get your job done faster and more efficiently, rather than concentrating on things like the point to rotate the line etc.
e.g there is a rotate function in Raphael which will allow you to rotate any object by a specific angle clockwise.
There is a function for translate, scale etc.
It supports SVG graphics as well.