trigonometry

How to find coordinates of a 2d equilateral triangle in C?

Deadly 提交于 2019-12-01 05:26:38
I have the coordinates (x,y) of 2 points. I want to build the third point so that these 3 points make an equilateral triangle. How can I calculate the third point? Thank you After reading the posts (specially vkit's) I produced this simple piece of code which will do the trick for one direction (remember that there are two points). The modification for the other case shold be trivial. #include<stdio.h> #include<math.h> typedef struct{ double x; double y; } Point; Point vertex(Point p1, Point p2){ double s60 = sin(60 * M_PI / 180.0); double c60 = cos(60 * M_PI / 180.0); Point v = { c60 * (p1.x

tan 45 gives me 0.9999

两盒软妹~` 提交于 2019-12-01 04:46:20
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? 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 has 4 decimal places, 1/3 would be represented as 0.3333 . When that's multiplied with 3 , you would get 0

sin v/s sinf function in C

﹥>﹥吖頭↗ 提交于 2019-12-01 04:19:26
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? 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 that doesn't have sinf you can implement it as: #define sinf(x) (float)sin((double)(x)) sin takes a double and

Converting result of Math.sin(x) into a result for degrees in java

泪湿孤枕 提交于 2019-12-01 04:11:36
I would like to convert the Math.sin(x) , where x in radians to a result which will give me as x in degrees not radians. I have used the normal method and java built in method of conversion between degrees and radians, but any argument I pass to the Math.sin() method is being treated as radians, thereby causing my conversion to be a futile effort. I want the output of a sin Input to be given as if the input is treated in degrees not radians like the Math.sin() method does. Java's Math library gives you methods to convert between degrees and radians: toRadians and toDegrees : public class

Calculate the function sin()

和自甴很熟 提交于 2019-12-01 04:08:19
问题 For my studies, I have to code an algorithm to calculate sin() with this function: However, in my algorithm, I have to keep the value of X between 0 and Pi/2. So, I wrote my algorithm but all the results are wrong. Here is my code: double sinX(double x){ double resultat = 0; int i; if(x < 0 || x > M_PI_2) x = fmod(x,M_PI_2); for(i = 1;i<=30;i++){ resultat += -1 * ((x*x)/(2*i*(2*i+1)))*(pow(-1,i-1))*((pow(x,2*i-1))/(factorielle(2*i-1))); } return resultat; } I didn't find the reason. Can you

Python numpy: Convert string in to numpy array

瘦欲@ 提交于 2019-12-01 03:38:27
问题 I have following String that I have put together: v1fColor = '2,4,14,5,0,0,0,0,0,0,0,0,0,0,12,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,6,0,0,0,0,1,0,0,0,0,0,0,0,0,0,20,9,0,0,0,2,2,0,0,0,0,0,0,0,0,0,13,6,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,8,0,0,0,1,2,0,0,0,0,0,0,0,0,0,17,17,0,0,0,3,6,0,0,0,0,0,0,0,0,0,7,5,0,0,0,2,0,0,0,0,0,0,0,0,0,0,4,3,0,0,0,1,1,0,0,0,0,0,0,0,0,0,6,6,0,0,0,2,3' I am treating it as a vector: Long story short its a forecolor of an image histogram: I have the following lambda function to

Inverse of Tan in python (tan-1)

一曲冷凌霜 提交于 2019-12-01 02:42:22
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? 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 you can simply multiply the radians by 180/pi. No need of importing ;) >>>from math import * >>>degrees(atan(1.18)) >>>49

Coordinate trigonometry - calculate midpoint in arc for flightpath

孤人 提交于 2019-12-01 02:34:12
I am trying to draw flightpaths on a map using SVGs. I'm using d3 on top of Leaflet, but the frameworks used shouldn't make a difference to my problem - it's trig. http://fiddle.jshell.net/zw8TR/26 The way I'm trying to do this is by creating a quadratic bezier curve (I'm open to other/easier ways if you know of any). What I need to calculate is 1 control point, perpendicular to the midpoint of each line. This point should always bias to a higher y value / latitude than the midpoint, to create an arc which looks like a flightpath. In my demo above, I found it's easier to debug exactly where

Converting result of Math.sin(x) into a result for degrees in java

≯℡__Kan透↙ 提交于 2019-12-01 01:40:01
问题 I would like to convert the Math.sin(x) , where x in radians to a result which will give me as x in degrees not radians. I have used the normal method and java built in method of conversion between degrees and radians, but any argument I pass to the Math.sin() method is being treated as radians, thereby causing my conversion to be a futile effort. I want the output of a sin Input to be given as if the input is treated in degrees not radians like the Math.sin() method does. 回答1: Java's Math

Convert radians to degrees, minutes, and seconds

怎甘沉沦 提交于 2019-12-01 01:24:10
I am looking on a way to convert decimals to degrees in C. For instance, the asin() function in C returns a decimal number but I need that number to be in degrees ° minutes ' seconds ". e.g. 1.5 would be 1°30'0" The asin function returns radians. There are 2 π radians in a circle. There are 360 degrees in a circle, 60 minutes in a degree, and 60 seconds in a minute. So there are 360*60*60 seconds in a circle. double radians = asin(opposite / hypotenuse); int totalSeconds = (int)round(radians * 360 * 60 * 60 / (2 * M_PI)); int seconds = totalSeconds % 60; int minutes = (totalSeconds / 60) % 60;