trigonometry

tan 45 gives me 0.9999

荒凉一梦 提交于 2019-12-19 06:37:10
问题 Why does tan 45 (0.7853981633974483 in radian) give me 0.9999 ? What's wrong with the following code? System.out.println(Math.tan(Math.toRadians(45.0)) ); I don't think there's any typo in here. So what's the solution here? 回答1: Floating point calculations will often lead to such inaccuracies. The problem is that numbers cannot be accurately represented within a fixed number of bits. To give you another example (in decimal), we all agree that 3 * (1/3) = 1 . However, if your calculator only

sin v/s sinf function in C

左心房为你撑大大i 提交于 2019-12-19 06:26:14
问题 I am trying to use the sinf function in my C Program but it gives me an undefined reference error under MSVC 6.0, however sin works fine. This make me curious to find the difference between sin and sinf . What is the logical difference between sin and sinf ? How can I implement my own sinf functionality? 回答1: sin takes a double and returns a double - sinf takes a float and returns a float. In other words sin is double precision and sinf is single precision. If you're using an old compiler

Knowing two points of a rectangle, how can I figure out the other two?

孤者浪人 提交于 2019-12-19 06:00:11
问题 Hey there guys, I'm learning processing.js, and I've come across a mathematical problem, which I can't seem to solve with my limited geometry and trigonometry knowledge or by help of Wikipedia. I need to draw a rectangle. To draw this rectangle, I need to know the coordinate points of each corner. All I know is x and y for the midpoints of the top and bottom of the box, and the length of all four sides. There is no guarantee on the orientation of the box. Any help? This seems like it should

Inverse of Tan in python (tan-1)

断了今生、忘了曾经 提交于 2019-12-19 05:03:49
问题 I am trying to calculate the inverse of tan in python, but it does not give me the correct value, for example, if I were to do the inverse tan of 1.18, math.atan(1.18) >>>math.atan(1.18) 0.8677 However, the correct answer is 49.720136931. What is the correct way to do than? 回答1: math.atan(x) returned in radian, if you want degree, convert it using math.degrees(x) Converts angle x from radians to degrees. >>> import math >>> math.degrees(math.atan(1.18)) 49.720136931043555 回答2: you can simply

Inverse of Tan in python (tan-1)

隐身守侯 提交于 2019-12-19 05:03:43
问题 I am trying to calculate the inverse of tan in python, but it does not give me the correct value, for example, if I were to do the inverse tan of 1.18, math.atan(1.18) >>>math.atan(1.18) 0.8677 However, the correct answer is 49.720136931. What is the correct way to do than? 回答1: math.atan(x) returned in radian, if you want degree, convert it using math.degrees(x) Converts angle x from radians to degrees. >>> import math >>> math.degrees(math.atan(1.18)) 49.720136931043555 回答2: you can simply

Calculating rotation along a path

狂风中的少年 提交于 2019-12-18 18:10:10
问题 I am trying to animate an object, let's say its a car. I want it go from point x1,y1,z1 to point x2,y2,z2 . It moves to those points, but it appears to be drifting rather than pointing in the direction of motion. So my question is: how can I solve this issue in my updateframe() event? Could you point me in the direction of some good resources? Thanks. 回答1: First off how do you represent the road? I recently done exactly this thing and I used Catmull-Rom splines for the road. To orient an

Calculating Distance Between 2 Cities [closed]

徘徊边缘 提交于 2019-12-18 10:24:25
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . How do you calculate the distance between 2 cities? 回答1: If you need to take the curvature of the earth into account, the Great-Circle distance is what you're looking for. The Wikipedia article probably does a better job of explaining how the formula works than me, and there's

Sine calculation with Taylor series not working

◇◆丶佛笑我妖孽 提交于 2019-12-18 09:22:00
问题 I wrote a sine function in Java, that should calculate the sine of x like My function looks like public static double sine(int x) { double result = 0; for(int n = 0; n <= 8; n++) { double temp = 2 * n + 1; result += Math.pow(-1, n) * Math.pow(x, temp) / fact(temp); // fact() calculates faculty } return result; } Only a few decimal places match to Math.sin(), but only if x is smaller then 6 and the limit of n equals to 8. Sometimes, if x is greater than 6 sine() returns even 4.106 or if limit

Sine calculation with Taylor series not working

自古美人都是妖i 提交于 2019-12-18 09:21:01
问题 I wrote a sine function in Java, that should calculate the sine of x like My function looks like public static double sine(int x) { double result = 0; for(int n = 0; n <= 8; n++) { double temp = 2 * n + 1; result += Math.pow(-1, n) * Math.pow(x, temp) / fact(temp); // fact() calculates faculty } return result; } Only a few decimal places match to Math.sin(), but only if x is smaller then 6 and the limit of n equals to 8. Sometimes, if x is greater than 6 sine() returns even 4.106 or if limit

Trying to fit a sine function to phased light curve

有些话、适合烂在心里 提交于 2019-12-18 07:24:28
问题 import numpy as np import matplotlib.pyplot as plt from lmfit import Model,Parameters f2= "KELT_N16_lc_006261_V01_west_tfa.dat" t2="TIMES" # file name NewData2 = np.loadtxt(t2, dtype=float, unpack=True) NewData = np.loadtxt(f2,dtype=float, unpack=True, usecols=(1,)) flux = NewData time= NewData2 new_flux=np.hstack([flux,flux]) # fold period = 2.0232 # period (must be known already!) foldTimes = ((time)/ period) # divide by period to convert to phase foldTimes = foldTimes % 1 # take fractional