trigonometry

Sin and Cos give unexpected results for well-known angles

别等时光非礼了梦想. 提交于 2019-11-26 06:49:42
问题 I am sure this is a really stupid question, but when I pass an angle of 180 degrees into c/c++\'s cos() and sin() functions I appear to receive an incorrect value. I know that it should be: sin of 0.0547 and cos of 0.99 but I get sin of 3.5897934739308216e-009 and cos of -1.00000 My code is: double radians = DegreesToRadians( angle ); double cosValue = cos( radians ); double sinValue = sin( radians ); DegreesToRadians() is: double DegreesToRadians( double degrees ) { return degrees * PI / 180

get cosine similarity between two documents in lucene

好久不见. 提交于 2019-11-26 06:33:17
问题 i have built an index in Lucene. I want without specifying a query, just to get a score (cosine similarity or another distance?) between two documents in the index. For example i am getting from previously opened IndexReader ir the documents with ids 2 and 4. Document d1 = ir.document(2); Document d2 = ir.document(4); How can i get the cosine similarity between these two documents? Thank you 回答1: When indexing, there's an option to store term frequency vectors. During runtime, look up the

How do Trigonometric functions work?

淺唱寂寞╮ 提交于 2019-11-26 03:32:59
问题 So in high school math, and probably college, we are taught how to use trig functions, what they do, and what kinds of problems they solve. But they have always been presented to me as a black box. If you need the Sine or Cosine of something, you hit the sin or cos button on your calculator and you\'re set. Which is fine. What I\'m wondering is how trigonometric functions are typically implemented. 回答1: First, you have to do some sort of range reduction. Trig functions are periodic, so you

How to use the PI constant in C++

烈酒焚心 提交于 2019-11-26 00:57:15
问题 I want to use the PI constant and trigonometric functions in some C++ program. I get the trigonometric functions with include <math.h> . However, there doesn\'t seem to be a definition for PI in this header file. How can I get PI without defining it manually? 回答1: On some (especially older) platforms (see the comments below) you might need to #define _USE_MATH_DEFINES and then include the necessary header file: #include <math.h> and the value of pi can be accessed via: M_PI In my math.h (2014

How to calculate the angle between a line and the horizontal axis?

夙愿已清 提交于 2019-11-26 00:39:44
问题 In a programming language (Python, C#, etc) I need to determine how to calculate the angle between a line and the horizontal axis? I think an image describes best what I want: Given (P1 x ,P1 y ) and (P2 x ,P2 y ) what is the best way to calculate this angle? The origin is in the topleft and only the positive quadrant is used. 回答1: First find the difference between the start point and the end point (here, this is more of a directed line segment, not a "line", since lines extend infinitely and

How do I calculate a point on a circle’s circumference?

吃可爱长大的小学妹 提交于 2019-11-26 00:23:36
问题 How can the following function be implemented in various languages? Calculate the (x,y) point on the circumference of a circle, given input values of: Radius Angle Origin (optional parameter, if supported by the language) 回答1: The parametric equation for a circle is x = cx + r * cos(a) y = cy + r * sin(a) Where r is the radius, cx,cy the origin, and a the angle. That's pretty easy to adapt into any language with basic trig functions. Note that most languages will use radians for the angle in

How does C compute sin() and other math functions?

只愿长相守 提交于 2019-11-26 00:06:53
问题 I\'ve been poring through .NET disassemblies and the GCC source code, but can\'t seem to find anywhere the actual implementation of sin() and other math functions... they always seem to be referencing something else. Can anyone help me find them? I feel like it\'s unlikely that ALL hardware that C will run on supports trig functions in hardware, so there must be a software algorithm somewhere , right? I\'m aware of several ways that functions can be calculated, and have written my own

How to use the PI constant in C++

假如想象 提交于 2019-11-25 23:54:44
I want to use the PI constant and trigonometric functions in some C++ program. I get the trigonometric functions with include <math.h> . However, there doesn't seem to be a definition for PI in this header file. How can I get PI without defining it manually? On some (especially older) platforms (see the comments below) you might need to #define _USE_MATH_DEFINES and then include the necessary header file: #include <math.h> and the value of pi can be accessed via: M_PI In my math.h (2014) it is defined as: # define M_PI 3.14159265358979323846 /* pi */ but check your math.h for more. An extract