trigonometry

Java: Trigonometry and double inaccuracy causing NaN

故事扮演 提交于 2019-12-12 23:47:39
问题 I have a distance formula using latitude and longitude: distance = EARTH_MILES_RADIUS * Math.acos(Math.sin(lat1 / RADIAN_CONV) * Math.sin(lat2 / RADIAN_CONV) + Math.cos(lat1 / RADIAN_CONV) * Math.cos(lat2 / RADIAN_CONV) * Math.cos((lng2 - lng1) / RADIAN_CONV)); lat1,lng1,lat2,lng2 are double primitives. They come to me as double primitives and there is nothing I can do about it. The problem is that when I have a pair of longitude or latitudes that are the same the formula sometimes returns

quaternion to angle

做~自己de王妃 提交于 2019-12-12 19:15:29
问题 Alright, so this is how I am doing it: float xrot = 0; float yrot = 0; float zrot = 0; Quaternion q = new Quaternion().fromRotationMatrix(player.model.getRotation()); if (q.getW() > 1) { q.normalizeLocal(); } float angle = (float) (2 * Math.acos(q.getW())); double s = Math.sqrt(1-q.getW()*q.getW()); // test to avoid divide by zero, s is always positive due to sqrt // if s close to zero then direction of axis not important if (s < 0.001) { // if it is important that axis is normalised then

python sine and cosine precision

这一生的挚爱 提交于 2019-12-12 17:21:53
问题 How to improve python sine and cosine precision? For example I want to use follow code (just calculate y = cos(acos(x)) for a random complex vector x): import numpy as np N = 100000 x = np.zeros(N)+1j*np.zeros(N) for k in range(0,N): x[k] = np.random.normal(0,500)+1j*np.random.normal(0,500) y = np.cos(np.arccos(x)) m= np.max(np.abs(x)) print np.max(np.abs(x-y)/m) y must be equal x . But my difference is approx 1E-9 . I think is too big. For example matlab returns less than 1E-15 for the same

JavaFX Rotating Camera Around a Pivot

ぃ、小莉子 提交于 2019-12-12 16:32:07
问题 Last year I posted a similar question, but due to it not being very descriptive and overall a mess I decided to rewrite it completely. I am making a simple 3D editor in JavaFX that has a camera movement similar to Blender or pretty much any other one. I added the rotation around the x-axis and then using trigonometric functions I calculated the other 2 rotations (y and z-axis). Both x and y-axis rotations are made relative to the pivot point, but the z rotation is always made relative to the

Finding 3rd point in Triangle using JavaScript

巧了我就是萌 提交于 2019-12-12 13:33:51
问题 Ok so I need to figure out in JavaScript how to plot a third point on a triangle. See diagram below. A and B will be randomized points (may be positive or negative depending on where they fall relative to the 0,0 origin.) thus A and B are known points (x and y). I already figured out how to plot C based on A and B. The distance between C and D I want control over. for example I want to say "The distance between C and D is now 20px... where is D?" So I guess for example purposes we can say

why is this sin method returning a wrong answer?

醉酒当歌 提交于 2019-12-12 13:14:02
问题 Hey, working on some categories and I've bumped up against a weird issue, im basically expanding on a calculator class to add some trig methods, and i am getting an incorrect value when i call the sin method in the return in the form of a double. i send a value of 100.7 to the method and it returns 0.168231, from what i can see the correct value should be = 0.939693 or there abouts. heres the code, I'm also attaching a link to the full project here: (thanks) http://files.me.com/knyck2/svpfd4

How can I determine whether it's faster to face an object rotating clockwise or counter clockwise?

拟墨画扇 提交于 2019-12-12 12:19:29
问题 I've been trying this to no avail for some days now, but basically I have some creatures and the player on the screen. What I want to happen is for the enemies to turn to face the player at a variable speed, rather than 'lock' into position and face the player immediately. What I am trying to do is work out whether it is faster for a given enemy to rotate clockwise or counter clockwise to face the player, but it's proving to be beyond my capabilities with trigonometry. Example: x in these

Basic trig: math.atan() issue

与世无争的帅哥 提交于 2019-12-12 11:06:52
问题 I'm having a little trouble with some basic trig. I'm doing some math homework, and I finally got bored of converting rectangular coordinates to polar coordinates and vice versa, so I decided to whip up a little Python program to help me with the conversions. However, Math.atan() is giving me a little trouble. Here's the code: def rect_to_polar_input(x, y): hypotenuse = math.sqrt((x * x) + (y * y)) tangent = float(y / x); angle = round(math.degrees(math.atan(tangent))); if x <= 0: if(y >=0):

Constrain MovieClip drag to a circle

半城伤御伤魂 提交于 2019-12-12 10:55:39
问题 ...well, to an incomplete circle. I have a draggable slider that looks like this: The blue bar has the instance name track and the pink dot has the instance name puck . I need the puck to be constrained within the blue area at all times, and this is where my maths failings work against me! So far I have the puck moving along the x axis only like this: private function init():void { zeroPoint = track.x + (track.width/2); puck.x = zeroPoint-(puck.width/2); puck.buttonMode = true; puck

Efficient calculation of cosine in python

左心房为你撑大大i 提交于 2019-12-12 08:55:04
问题 I generate some time-series out of a theoretical power spectral density. Basically, my function in time-space is given by X(t) = SUM_n sqrt(a_n) + cos(w_n t + phi_n) , where a_n is the value of the PSD at a given w_n and phi is some random phase. To get a realistic timeseries, i have to sum up 2^25 modes, and my t of course is sized 2^25 as well. If i do that with python, this will take some weeks... Is there any way to speed this up? Like some vector calculation? t_full = np.linspace(0,1e-2