trigonometry

How do Trigonometric functions work?

孤人 提交于 2019-11-26 11:31:41
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. First, you have to do some sort of range reduction. Trig functions are periodic, so you need to reduce arguments down to a standard interval. For starters, you could reduce angles to be between 0 and

Rotate line around center point given two vertices

我是研究僧i 提交于 2019-11-26 09:50:53
问题 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

Fast transcendent / trigonometric functions for Java

故事扮演 提交于 2019-11-26 09:26:18
问题 Since the trigonometric functions in java.lang.Math are quite slow: is there a library that does a quick and good approximation? It seems possible to do a calculation several times faster without losing much precision. (On my machine a multiplication takes 1.5ns, and java.lang.Math.sin 46ns to 116ns). Unfortunately there is not yet a way to use the hardware functions. UPDATE: The functions should be accurate enough, say, for GPS calculations. That means you would need at least 7 decimal

Calculating bounding box a certain distance away from a lat/long coordinate in Java

只谈情不闲聊 提交于 2019-11-26 09:19:58
问题 Given a coordinate (lat, long), I am trying to calculate a square bounding box that is a given distance (e.g. 50km) away from the coordinate. So as input I have lat, long and distance and as output I would like two coordinates; one being the south-west (bottom-left) corner and one being the north-east (top-right) corner. I have seen a couple of answers on here that try to address this question in Python, but I am looking for a Java implementation in particular. Just to be clear, I intend on

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

亡梦爱人 提交于 2019-11-26 08:09:37
问题 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

Calculate second point knowing the starting point and distance

♀尐吖头ヾ 提交于 2019-11-26 07:59:11
问题 using a Latitude and Longitude value (Point A), I am trying to calculate another Point B, X meters away bearing 0 radians from point A. Then display the point B Latitude and Longitude values. Example (Pseudo code): PointA_Lat = x.xxxx; PointA_Lng = x.xxxx; Distance = 3; //Meters bearing = 0; //radians new_PointB = PointA-Distance; I was able to calculate the distance between two Points but what I want to find is the second point knowing the distance and bearing. Preferably in PHP or

Java BigDecimal trigonometric methods

限于喜欢 提交于 2019-11-26 07:49:18
问题 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

Finding Signed Angle Between Vectors

风流意气都作罢 提交于 2019-11-26 07:30:42
问题 How would you find the signed angle theta from vector a to b? And yes, I know that theta = arccos((a.b)/(|a||b|)). However, this does not contain a sign (i.e. it doesn\'t distinguish between a clockwise or counterclockwise rotation). I need something that can tell me the minimum angle to rotate from a to b. A positive sign indicates a rotation from +x-axis towards +y-axis. Conversely, a negative sign indicates a rotation from +x-axis towards -y-axis. assert angle((1,0),(0,1)) == pi/2. assert

Calculating the position of points in a circle

两盒软妹~` 提交于 2019-11-26 07:25:02
问题 I\'m having a bit of a mind blank on this at the moment. I\'ve got a problem where I need to calculate the position of points around a central point, assuming they\'re all equidistant from the center and from each other. The number of points is variable so it\'s DrawCirclePoints(int x) I\'m sure there\'s a simple solution, but for the life of me, I just can\'t see it :) 回答1: A point at angle theta on the circle whose centre is (x0,y0) and whose radius is r is (x0 + r cos theta, y0 + r sin

Find cosine similarity between two arrays

允我心安 提交于 2019-11-26 07:24:36
问题 I\'m wondering if there is a built in function in R that can find the cosine similarity (or cosine distance) between two arrays? Currently, I implemented my own function, but I can\'t help but think that R should already come with one. 回答1: These sort of questions come up all the time (for me--and as evidenced by the r -tagged SO question list--others as well): is there a function, either in R core or in any R Package, that does x? and if so, where can i find it among the +2000 R Packages in