天道酬勤,学无止境

math

Java code to get rotation angle around an axis from quaternion

I am really struggeling to find the correct way to get the rotation angle around a single axis from an arbitrary quaternion. So other words I want to find the portion of the expressed rotation around a specified axis (in my case the Z-axis of the coordinate system, but an arbitrary solution would be nice) in terms of the angle. Can anyone point out to achieve this? Ideally some java fragment would be nice. I tried the solution proposed in 1 for attitude, which is: asin(2*qx*qy + 2*qz*qw) However, this fails in some cases, e.g. a single rotation around the Z-axis with more than 0.6 * PI.

2021-09-24 16:19:55    分类:问答    java   math   geometry   quaternions

Math.pow with Command line arguments

I need to get the power value of a given number by user (as a command line argument) This is my code and it has comes up with a compilation error. Can anyone please help me ? class SquareRoot{ public static void main(String args []){ double power = Math.pow(args[0]); System.out.println("Your squared value is " + power); } }

2021-09-24 07:48:11    分类:问答    java   math   command-line

如何查找由纬度和经度表示的两条线段之间是否存在交点(How to find if an intersection occurs between two line segments represented by a Latitude and Longitude)

问题 在我正在开发的应用程序中,我有许多由纬度和经度值表示的线。 我想检查另一条线是否在任何一点与这些线中的任何一条相交。 假设我有一条线 AB 我想知道它是否在任何一点与线 CD 相交。 上面的第一个和第二个例子不会导致交叉,而第三个例子会。 对于我的场景,实际的交叉点对于应用程序的运行来说并不是必需的,因此只需要对交叉点进行简单的“是/否”即可。 我知道使用纬度和经度值并不是严格准确的,因为世界是一个椭球体,因此需要先转换这些值。 但是,为了证明我正在研究的概念,我正在寻找一种适用于任何线段方向的线交点算法。 我见过几种算法,但没有设法让任何算法在实践中发挥作用。 目前我一直在看这里提到的方法如何计算地图上的线段交点 我正在使用下面的代码,只是使用简单的坐标来证明它有效,但从我的测试来看,即使它们不存在,它也会返回交点。 double lineABxLength = bX - aX; double lineCDxLength = dX - cX; double lineAByLength = bY - aY; double lineCDyLength = dY - cY; double lineDenomiter = (lineABxLength * lineCDyLength) - (lineAByLength * lineCDxLength); double a = (aX

2021-09-24 07:06:06    分类:技术分享    java   android   math   line   intersection

PHP Get Experience by Level

I have this piece of code that loops 1 through 99 and is a formula. function getExperienceByLevel ($maxLevel) { $levels = array (); $current = 0; for ($i = 1; $i <= $maxLevel; $i++) { $levels[$i - 1] = floor ($current / 4); $current += floor($i+300*pow(2, ($i/9.75))); } return $levels; } First you initiate it like so $aLevels = getExperienceByLevel(99); then to see how much EXP you need to get to level 6 you do this echo $aLevels[5]; since it's an array. Now I'm trying to do reverse. Get Level by EXP. function getLevelByExp($exp) { $myLevel = 0; $aLevels = getExperienceByLevel(99); for ($i = 1

2021-09-24 06:56:28    分类:问答    php   math   numbers

将局部四元数旋转转换为全局(陀螺仪)(Translate Local quaternion rotation into global (gyro))

问题 我需要一种方法来从局部获取全局参考系中旋转的欧拉角。 我正在使用 c#、wpf 3d 和陀螺仪。 我在屏幕上有一个地球仪,它应该以与陀螺仪相同的方式移动。 由于陀螺仪发送相对于自身的运动,我需要使用四元数来保持对象的状态并更新它,但我被卡住了。 如果我执行以下操作: var qu=eulerToQ(Gyro.X,Gyro.Y,Gyro.Z); GlobalQu = Quaternion.Multiply(qu, GlobalQu); IT 在一个轴上正确旋转。 当我在一个方向上旋转 A 然后在另一个方向上旋转 B 时,物体和陀螺仪的旋转不再在同一方向上,因为上述适用于绝对旋转(相对于世界)。 例如: var qu=eulerToQ(KeyboardValue1,KeyboardValue2,KeyboardValue3); GlobalQu = qu; 这是有效的,因为我一直在全局轴上通过键盘增加滚动,俯仰,偏航,即键盘值。 陀螺仪在 LOCAL 轴上发送旋转。 切换四元数旋转的顺序无济于事 var qu=eulerToQ(Giro.X,Giro.Y,Giro.Z); GlobalQu = Quaternion.Multiply(GlobalQu,qu); 回答1 这实际上是正确的方法。 如果你乘以 globalQuaternion * newQuaternion

2021-09-24 06:42:50    分类:技术分享    c#   math   3d   quaternions   euler-angles

Get powers of a perfect power number

I have a problem which is to find the 2 powers of any number (numbers that don't have any powers such as 5 will return null), powers being and 2 integer numbers that when added power to return the said number. Here are some examples: 4 -> {2, 2} 5 -> null 6 -> null 7 -> null 8 -> {2, 3} 10 -> null etc... Although my code below works, however its too slow, when passed through the problem (about 100 integer.max values) it takes over the set time (16 seconds), anything I could to optimize this code? public static int[] isPerfectPower(int n) { int limit = (int)Math.round((n/((double)5/2))); for

2021-09-24 05:41:44    分类:问答    java   algorithm   performance   math

Translating lat/lon coordinate on rotated/scaled maps

I need to indicate a lat/lon coordinate in an old map like this: http://www.davidrumsey.com/luna/servlet/detail/RUMSEY~8~1~3017~90020003:Topographical-Map-Of-The-City-and-C Projected on Google Maps: http://rumsey.geogarage.com/maps/g2784000.html I know the bounding box of the map as well as the dimensions of the image in pixels, but I couldn't figure out how to locate a lat/lon within this map. Upper left is (40.698291,-74.079051), Lower Left (40.659855,-73.979638), Lower Right (40.855232,-73.835582) and Upper Right (40.882919,-73.940263). Is there a standard formula on how to do locate a lot

2021-09-24 05:26:52    分类:问答    math   maps

Calculate logarithm by hand

I'd like to calculate the mathematical logarithm "by hand"... ... where stands for the logarithmBase and stands for the value. Some examples (See Log calculator): The base 2 logarithm of 10 is 3.3219280949 The base 5 logarithm of 15 is 1.6826061945 ... Hoever - I do not want to use a already implemented function call like Math.ceil, Math.log, Math.abs, ..., because I want a clean native solution that just deals with +-*/ and some loops. This is the code I got so far: function myLog(base, x) { let result = 0; do { x /= base; result ++; } while (x >= base) return result; } let x = 10, base = 2

2021-09-24 05:15:49    分类:问答    javascript   math   numbers   integer   logarithm

spoj 阶乘(超出时间限制错误)。 如何改进我的解决方案? [关闭](spoj factorial (time limit exceeded error). How can i improve my solution? [closed])

问题 关闭。 这个问题是题外话。 它目前不接受答案。 想改善这个问题吗? 更新问题,使其成为 Stack Overflow 的主题。 8 年前关闭。 改进这个问题 这是我关于 spoj 问题的链接。 我已经尝试使用递归和非递归。 但我收到超出时间限制的错误。 如何改进我的解决方案? 我已经展示了下面的两种解决方案。 A) 非递归方法。 #include <stdio.h> int main() { long long int t,n,i,j=0,y; unsigned long long int fact; scanf("%lld",&t); i=t; while(i>0) { scanf("%lld",&n); fact=1; for(y=1;y<=n;y++) fact=fact*y; j=0; while(fact%10==0) j++; printf("\n%lld",j); i--; } return 0; } B) 非递归 #include <stdio.h> unsigned long long int fact(long long int); int main() { long long int t,n,i,j=0; unsigned long long int y; scanf("%lld",&t); i=t; while(i>0) { scanf("%lld"

2021-09-24 04:54:12    分类:技术分享    c   math

在 jQuery 中包含指数?(Including Exponents in jQuery?)

问题 你如何在 JQuery 中实现指数? 我正在修改这个: $.fn.sumValues = function() { var sum = 0; this.each(function() { if ( $(this).is(':input') ) { var val = $(this).val(); } else { var val = $(this).text(); } sum += parseFloat( ('0' + val).replace(/[^0-9-\.]/g, ''), 10 ); }); return sum; 和 $(document).ready(function() { $('input.price').bind('keyup', function() { $('span.total').html( $('input.price').sumValues() ); }); 从用户输入计算更复杂的求和公式。 公式本身是(a 到 g 是用户输入): 步骤 1) X=((1+(a/100))^b)*(c*12) 步骤 2) X+d=e 步骤 3) efg=h 你能帮我更有效地实施吗? 回答1 var X = Math.pow(1+(a/100), b)*(c*12); var e = X+d; var h = e-f-g; Math.pow(base

2021-09-24 03:02:34    分类:技术分享    jquery   math   implementation   equation   exponent