trigonometry

Rotate line around center point given two vertices

喜你入骨 提交于 2019-11-27 04:40:37
I've been trying to rotate a bunch of lines by 90 degrees (that together form a polyline). Each line contains two vertices, say (x1, y1) and (x2, y2). What I'm currently trying to do is rotate around the center point of the line, given center points |x1 - x2| and |y1 - y2|. For some reason (I'm not very mathematically savvy) I can't get the lines to rotate correctly. Could someone verify that the math here is correct? I'm thinking that it could be correct, however, when I set the line's vertices to the new rotated vertices, the next line may not be grabbing the new (x2, y2) vertex from the

Proper Trigonometry For Rotating A Point Around The Origin

送分小仙女□ 提交于 2019-11-27 03:51:25
问题 Do either of the below approaches use the correct mathematics for rotating a point? If so, which one is correct? POINT rotate_point(float cx,float cy,float angle,POINT p) { float s = sin(angle); float c = cos(angle); // translate point back to origin: p.x -= cx; p.y -= cy; // Which One Is Correct: // This? float xnew = p.x * c - p.y * s; float ynew = p.x * s + p.y * c; // Or This? float xnew = p.x * c + p.y * s; float ynew = -p.x * s + p.y * c; // translate point back: p.x = xnew + cx; p.y =

Why does Math.cos(90 * Math.PI/180) yield 6.123031769111… and not zero? [duplicate]

好久不见. 提交于 2019-11-27 01:50:23
问题 This question already has an answer here: Is floating point math broken? 31 answers I convert degrees to radians (degrees * Math.PI/180) but why does the following: Math.cos(90 * Math.PI/180) yield 6.123031769111... and not zero? I'm trying to perform 2D rotations uses matrixes and the results are completely out of whack. 回答1: The output of Math.cos(90 * Math.PI/180) is 6.123031769111886e-17 Notice the e-17 at the end, which means that this number is 6.123 x 10 -17 . This is a number so

How is arctan implemented?

纵然是瞬间 提交于 2019-11-27 01:38:39
问题 Many implementation of the library goes deep down to FPATAN instuction for all arc-functions. How is FPATAN implemented? Assuming that we have 1 bit sign, M bits mantissa and N bits exponent, what is the algorithm to get the arctangent of this number? There should be such algorithm, since the FPU does it. 回答1: Trigonometric functions do have pretty ugly implementations that are hacky and do lots of bit fiddling. I think it will be pretty hard to find someone here that is able to explain an

Draw a line at a specific angle in Java

大憨熊 提交于 2019-11-27 01:03:38
问题 Let's say I have an (x,y) that is always the same for the start point of a line and an (x,y) that changes for the end point of that same line. The line is also always 40px long. At the start of the program the line originates in a vertical orientation (lets call it 0 degrees). Based on a user input I need the line to be redrawn a specific number of degrees from its origin by changing only the end (x,y). SOME MORE FOOD FOR THOUGHT IF YOU NEED IT: I'm in a rut trying to calculate this and make

How do I calculate the cosine similarity of two vectors?

我只是一个虾纸丫 提交于 2019-11-27 00:04:28
问题 How do I find the cosine similarity between vectors? I need to find the similarity to measure the relatedness between two lines of text. For example, I have two sentences like: system for user interface user interface machine … and their respective vectors after tF-idf, followed by normalisation using LSI, for example [1,0.5] and [0.5,1] . How do I measure the smiliarity between these vectors? 回答1: public class CosineSimilarity extends AbstractSimilarity { @Override protected double

Java BigDecimal trigonometric methods

北城以北 提交于 2019-11-26 23:14:23
I am developing a mathematical parser which is able to evaluate String like '5+b*sqrt(c^2)' . I am using ANTLR for the parsing and make good progress. Now I fell over the Java class BigDecimal and thought: hey, why not thinking about precision here. My problem is that the Java API does not provide trigonometric methods for BigDecimal s like java.lang.Math . Do you know if there are any good math libraries like Apache Commons out there that deal with this problem? The other questions is how to realize the power method so that I can calculate 4.9 ^ 1.4 with BigDecimal s. Is this possible? A book

What is the method for converting radians to degrees?

ぐ巨炮叔叔 提交于 2019-11-26 22:30:13
问题 I run into this occasionally and always forget how to do it. One of those things that pop up ever so often. Also, what's the formula to convert angles expressed in radians to degrees and back again? 回答1: radians = degrees * (pi/180) degrees = radians * (180/pi) As for implementation, the main question is how precise you want to be about the value of pi. There is some related discussion here 回答2: a complete circle in radians is 2*pi. A complete circle in degrees is 360. To go from degrees to

Calculating the angle between two lines without having to calculate the slope? (Java)

不想你离开。 提交于 2019-11-26 22:05:52
I have two Lines: L1 and L2. I want to calculate the angle between the two lines. L1 has points: {(x1, y1), (x2, y2)} and L2 has points: {(x3, y3), (x4, y4)} . How can I calculate the angle formed between these two lines, without having to calculate the slopes? The problem I am currently having is that sometimes I have horizontal lines (lines along the x-axis) and the following formula fails (divide by zero exception): arctan((m1 - m2) / (1 - (m1 * m2))) where m1 and m2 are the slopes of line 1 and line 2 respectively. Is there a formula/algorithm that can calculate the angles between the two

Make Swift Assume Degrees for Trigonometry Calculations

旧城冷巷雨未停 提交于 2019-11-26 21:41:00
问题 Is it possible to change a setting, property, etc in Swift for iOS so that it assumes degrees for trigonometry calculations rather than radians? For example sin(90) would be evaluated to 1 . I have: let pi = 3.14 var r2d = 180.0/pi var d2r = pi/180 ... but the conversions are getting really involved for some of the long trig equations. 回答1: As already said in the other answers, there are no trigonometric functions in the standard library that take the arguments in degrees. If you define your