trigonometry

Inconsistency with Math.Round()

馋奶兔 提交于 2019-12-01 20:47:38
I have two functions that are intended to contain angles between (-180,180] and (-π,π]. The intent is that given any angle from -inf to +inf it will retain the equivalent angle in the intervals specified. For example the angle for 1550° is 110°. public double WrapBetween180(double angle) { return angle - 360d * Math.Round(angle / 360d, MidpointRounding.AwayFromZero); } public double WrapBetweenPI(double angle) { const double twopi = 2d * Math.PI; return angle - twopi * Math.Round(angle / twopi, MidpointRounding.AwayFromZero); } which yields the following results WrapBetween180(-180) = -180

R: Strange trig function behavior

无人久伴 提交于 2019-12-01 18:48:52
As a Matlab user transitioning to R, I have ran across the problem of applying trigonometric functions to degrees. In Matlab there are trig functions for both radians and degrees (e.g. cos and cosd, respectively). R seems to only include functions for radians, thus requiring me to create my own (see below) cosd<-function(degrees) { radians<-cos(degrees*pi/180) return(radians) } Unfortunately this function does not work properly all of the time. Some results are shown below. > cosd(90) [1] 6.123234e-17 > cosd(180) [1] -1 > cosd(270) [1] -1.836970e-16 > cosd(360) [1] 1 I'd like to understand

jQuery animating along a sine wave

别说谁变了你拦得住时间么 提交于 2019-12-01 18:33:57
I've spent a couple days at this and I give up. I'm trying to get an object to animate along a sine wave infinitely. It should not end after the first period. Main Problem: The cycle ends at approx 1 1/3 Pi rather than just Pi. This extra movement ruins the animation. I'm stuck here: http://jsfiddle.net/WPnQG/12/ . After each period, it skips about 40 pixels and then continues along its path. This is the problem I can't get past -- the value it ends at and proceeds to restart at are not equal, so the object appears to skip around. Could anyone help a man out? Thanks I am using the jQuery Path

Java Math.cos() Method Does Not Return 0 When Expected

别说谁变了你拦得住时间么 提交于 2019-12-01 15:58:49
Using Java on a Windows 7 PC (not sure if that matters) and calling Math.cos() on values that should return 0 (like pi/2) instead returns small values, but small values that, unless I'm misunderstanding, are much greater than 1 ulp off from zero. Math.cos(Math.PI/2) = 6.123233995736766E-17 Math.ulp(Math.cos(Math.PI/2)) = 1.232595164407831E-32 Is this in fact within 1 ulp and I'm simply confused? And would this be an acceptable wrapper method to resolve this minor inaccuracy? public static double cos(double a){ double temp = Math.abs(a % Math.PI); if(temp == Math.PI/2) return 0; return Math.cos

about cosine similarity

╄→尐↘猪︶ㄣ 提交于 2019-12-01 11:08:41
问题 I am finding cosine similarity between documents.. I did it like this D1=(8,0,0,1) where 8,0,0,1 are the tf-idf scores of the terms t1, t2, t3 , t4 D2=(7,0,0,1) cos(theta) = (56 + 0 + 0 + 1) / sqrt(64 + 49) sqrt(1 +1 ) which comes out to be cos(theta)= 5 Now what do I evaluate from this value... I don't get it what does cos(theta)=5 signify about the similarity between them... Am I doing things right? 回答1: The denominator is wrong. The cosine similarity is defined as D1 · D2 sim = ———————————

Intersection between two Arcs? (arc = distance between pair of angles)

左心房为你撑大大i 提交于 2019-12-01 10:33:37
I'm trying to find a way to calculate the intersection between two arcs. I need to use this to determine how much of an Arc is visually on the right half of a circle, and how much on the left. I though about creating an arc of the right half, and intersect that with the actual arc. But it takes me wayyy to much time to solve this, so I thought about asking here - someone must have done it before. Edit: I'm sorry the previous illustration was provided when my head was too heavy after crunching angles. I'll try to explain again: In this link you can see that I cut the arc in the middle to two

Intersection between two Arcs? (arc = distance between pair of angles)

被刻印的时光 ゝ 提交于 2019-12-01 08:30:40
问题 I'm trying to find a way to calculate the intersection between two arcs. I need to use this to determine how much of an Arc is visually on the right half of a circle, and how much on the left. I though about creating an arc of the right half, and intersect that with the actual arc. But it takes me wayyy to much time to solve this, so I thought about asking here - someone must have done it before. Edit: I'm sorry the previous illustration was provided when my head was too heavy after crunching

Javascript: Find point on perpendicular line always the same distance away

岁酱吖の 提交于 2019-12-01 08:03:44
I'm trying to find a point that is equal distance away from the middle of a perpendicular line. I want to use this point to create a Bézier curve using the start and end points, and this other point I'm trying to find. I've calculated the perpendicular line, and I can plot points on that line, but the problem is that depending on the angle of the line, the points get further away or closer to the original line, and I want to be able to calculate it so it's always X units away. Take a look at this JSFiddle which shows the original line, with some points plotted along the perpendicular line:

Cosine similarity of 2 DTMs in R

限于喜欢 提交于 2019-12-01 07:26:58
问题 I have 2 Document term matrices: DTM 1 has say 1000 vectors(1000 docs) and DTM2 has 20 vectors (20 docs) So basically I want to compare each document of DTM1 against DTM2 and would want to see which DTM1 docs are closest to which DTM2 docs using the cosine function. Any pointers would help! I have created a cosine matrix using the "slam" package. Docs –glyma –ie –initi –stafford ‘bureaucratic’ ‘empti ‘holi ‘incontrovert 1 0.000000 0 0.000000 0.000000 0.000000 0 0 0 2 0.000000 0 0.000000 0

Android get normalized acceleration

谁说胖子不能爱 提交于 2019-12-01 05:30:31
I wish to get the acceleration vector of an Android phone. The problem is, the accelerometer coordinates are relative to the phone's rotation. What I want is the "absolute" acceleration, i.e., it should return the same values whichever way the phone is facing. (I want to detect if a user that is skiing is sliding down a slope without using GPS. I also need to be able to differentiate sliding and going up the chairlift.) I can probably get those values by combining the accelerometer with the gyroscope, but I have no idea how I could offset the accelerometer's values with the gyroscope's. Is