trigonometry

Assembly code for sin(x) using Taylor expansion

ε祈祈猫儿з 提交于 2019-12-03 12:10:38
In x86 Linux, how can I implement sin(x) in assembly code using Taylor Expansion ? Would this article help you? http://www.coranac.com/2009/07/sines/ It has a couple of algorithms for computing approximate sin(x) values, with both C and assembly versions. Granted, it's ARM assembly, but the gist of it should translate easily to x86 or similar. You don't state which CPU architecture so I'm assuming x86. The simplist (and possibly most inefficient) way would be to write the formula in RPN, which can be mapped almost directly to FPU instructions. Example, algebraic formula : x - (x^3/3!) + (x^5/5

Using “sincos” in Java

萝らか妹 提交于 2019-12-03 09:01:00
问题 In a lot of situations I not only need the sine, but also the cosine of the same parameter. For C, there is the sincos function in the common unix m math library. And actually, at least on i386, this should be a single assembly instruction, fsincos . sincos, sincosf, sincosl - calculate sin and cos simultaneously I guess these benefits exist because there is an obvious overlap in computing sine and cosine: sin(x)^2 + cos(x)^2 = 1 . But AFAIK it does not pay off to try to shortcut this as cos

sine wave glissando from one pitch to another in Numpy

独自空忆成欢 提交于 2019-12-03 08:39:37
I have been working on a program where I need to slowly and smoothly change the pitch of a sine wave from one pitch to another. I am able to get an array of the frequency the pitch should be at any given moment (for instance, [440, 526.5, 634.2 794.8, 880], though much, much longer) but it seems I am unable to actually apply that frequency to a wave. My best attempt is: numpy.sin(2*math.pi*x*freq/self.sample_rate) where "freq" is the array of frequencies and x is an enumeration array ([0,1, 2, 3, 4...]). This method sort of works, however it makes the frequency go above the expected frequency,

Rotate rectangle around a point

烂漫一生 提交于 2019-12-03 07:40:01
How would I get 4 points rotated a certain degrees around a pointer to form a rectangle? I can rotate a point around a point, but I can't offset it to make a rectangle that isn't distorted. If you can rotate a point around a point then it should be easy to rotate a rectangle - you just rotate 4 points. Here is a js function to rotate a point around an origin: function rotate_point(pointX, pointY, originX, originY, angle) { angle = angle * Math.PI / 180.0; return { x: Math.cos(angle) * (pointX-originX) - Math.sin(angle) * (pointY-originY) + originX, y: Math.sin(angle) * (pointX-originX) + Math

Find the Angle between two Bearings

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 07:19:49
Given two bearing, how do I find the smallest angle between them? So for example if 1 heading is 340 degrees and the second is 10 degrees the smallest angle will be 30 degrees. I've attached a picture to show what I mean. I've tried subtracting one from the other but that didn't work because of the wrap around effect of a circle. I've also tried using negative degrees (180 - 359 being -180 to 0) but that got messed up when trying to calculate the angle between positive and negative number. I'm sure there must be an easier way that having lots of if statements. Thank for your help. Adam BTW.

Python Uniform distribution of points on 4 dimensional sphere

风格不统一 提交于 2019-12-03 07:10:49
I need a uniform distribution of points on a 4 dimensional sphere. I know this is not as trivial as picking 3 angles and using polar coordinates. In 3 dimensions I use from random import random u=random() costheta = 2*u -1 #for distribution between -1 and 1 theta = acos(costheta) phi = 2*pi*random x=costheta y=sin(theta)*cos(phi) x=sin(theta)*sin(phi) This gives a uniform distribution of x, y and z. How can I obtain a similar distribution for 4 dimensions? A standard way , though, perhaps not the fastest , is to use Muller's method to generate uniformly distributed points on an N-sphere:

How to look up sine of different frequencies from a fixed sized lookup table?

爷,独闯天下 提交于 2019-12-03 07:08:11
I am sampling a sine wave at 48 kHz, the frequency range of my sine wave can vary from 0 to 20000 Hz with a step of about 100 Hz. I am using a lookup table approach. So I generate 4096 samples for a sine wave for 4096 different phases. I think the general idea behind this to increment the step size and use different step sizes for different frequncy. So I do the following (pseudo code). But I am not sure how the step size is going to be related to the frequency I want to generate the samples of the sine wave of? For example if my frequency is 15000 Hz what would be the step size that I have to

Calculating degrees between 2 points with inverse Y axis

試著忘記壹切 提交于 2019-12-03 04:14:52
问题 I'm creating a simple 2D game in javascript/canvas. I need to figure out the angle of a certain object relative to my position. So: say I'm at (10,10) and the object is at (10,5) - that would result in 90 degrees (as positive Y is down, negative Y is up) (10,10) vs (10,15) would be 270 degrees. How would I go about this? 回答1: Suppose you're at (a, b) and the object is at (c, d). Then the relative position of the object to you is (x, y) = (c - a, d - b). Then you could use the Math.atan2()

rotating a quaternion on 1 axis?

一个人想着一个人 提交于 2019-12-03 00:40:59
I have a model rotated by a quaternion. I can only set the rotation, I can't add or subtract from anything. I need to get the value of an axis, and than add an angle to it (maybe a degree or radian?) and than re-add the modified quaternion. How can I do this? (answer on each axis). You can multiply two quaternions together to produce a third quaternion that is the result of the two rotations. Note that quaternion multiplication is not commutative, meaning order matters (if you do this in your head a few times, you can see why). You can produce a quaternion that represents a rotation by a given

Find the normal angle of the face of a triangle in 3D, given the co-ordinates of its vertices

99封情书 提交于 2019-12-02 23:07:41
As you may be able to tell from this screenshot , I am trying to make a physics engine for a platformer I am working on, but I have run into a definite problem: I need to be able to find out the angle of any one of the triangles that you can see make up this mesh, so that I can work out the rotation and therefore angular acceleration of the player on that triangle. I can use an algorithm that I created to find the locations of all 3 points of any triangle that the player is in contact with, but I don't know how to use those points to work out the rotation of the triangle. By the rotation, I