angle

The X angle between two 3D vectors?

北慕城南 提交于 2019-12-18 13:36:09
问题 I have two 3D vectors called A and B that both only have a 3D position. I know how to find the angle along the unit circle ranging from 0-360 degrees with the atan2 function by doing: EDIT: (my atan2 function made no sense, now it should find the "y-angle" between 2 vectors): toDegrees(atan2(A.x-B.x,A.z-B.z))+180 But that gives me the Y angle between the 2 vectors. I need to find the X angle between them. It has to do with using the x, y and z position values. Not the x and z only, because

Why do sin(45) and cos(45) give different results? [duplicate]

不问归期 提交于 2019-12-18 07:12:29
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 4 years ago . This is something I wasn't expecting. I know these numbers are not 100% exact, but I wasn't expecting complementary angles giving different results of sin and cos : This following function returns 0.70710678118654746000000... sin(45 * PI / 180.0); while this follwing function returns 0.70710678118654757000000... cos(45 * PI / 180.0); so, it's: 0.707106781186547**46**000000... vs 0

Why do sin(45) and cos(45) give different results? [duplicate]

元气小坏坏 提交于 2019-12-18 07:12:26
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 4 years ago . This is something I wasn't expecting. I know these numbers are not 100% exact, but I wasn't expecting complementary angles giving different results of sin and cos : This following function returns 0.70710678118654746000000... sin(45 * PI / 180.0); while this follwing function returns 0.70710678118654757000000... cos(45 * PI / 180.0); so, it's: 0.707106781186547**46**000000... vs 0

Retrieve a positive or a negative angle from 3 points

醉酒当歌 提交于 2019-12-18 04:21:07
问题 I am rotating points around a center point in 2D space. The points are the center point, the old mouse position, and the new mouse position. My rotation function works fine, and I can calculate the angle perfectly. But I want to calculate a negative angle if the user is moving their mouse in a direction which should be interpreted as counter-clockwise. For example, moving the mouse toward the right (positive x-axis) should rotate clockwise if you are above (less than) the y value of the

How to calculate an angle from points?

本小妞迷上赌 提交于 2019-12-17 22:21:38
问题 I want to get a simple solution to calculate the angle of a line (like a pointer of a clock). I have 2 points: cX, cY - the center of the line. eX, eY - the end of the line. The result is angle (0 <= a < 360). Which function is able to provide this value? 回答1: You want the arctangent: dy = ey - cy dx = ex - cx theta = arctan(dy/dx) theta *= 180/pi // rads to degs Erm, note that the above is obviously not compiling Javascript code. You'll have to look through documentation for the arctangent

Angle gradient in canvas

拈花ヽ惹草 提交于 2019-12-17 09:51:34
问题 I'm looking for a code that permits to have this effect on a canvas' stroke. I've already got an animated circular stroke, I only need to get the ANGLE gradient, not linear and not radial. I've got only 3 colours. The existing one is available here (the review rating) 回答1: A context strokeStyle can be a gradient: // create a gradient gradient = ctx.createLinearGradient(xStart, yStart, xEnd, yEnd); gradient.addColorStop(0.0,"blue"); gradient.addColorStop(1.0,"purple"); // stroke using that

Angles between two n-dimensional vectors in Python

戏子无情 提交于 2019-12-17 03:54:52
问题 I need to determine the angle(s) between two n-dimensional vectors in Python. For example, the input can be two lists like the following: [1,2,3,4] and [6,7,8,9] . 回答1: import math def dotproduct(v1, v2): return sum((a*b) for a, b in zip(v1, v2)) def length(v): return math.sqrt(dotproduct(v, v)) def angle(v1, v2): return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2))) Note : this will fail when the vectors have either the same or the opposite direction. The correct implementation is

Angles between two n-dimensional vectors in Python

混江龙づ霸主 提交于 2019-12-17 03:54:04
问题 I need to determine the angle(s) between two n-dimensional vectors in Python. For example, the input can be two lists like the following: [1,2,3,4] and [6,7,8,9] . 回答1: import math def dotproduct(v1, v2): return sum((a*b) for a, b in zip(v1, v2)) def length(v): return math.sqrt(dotproduct(v, v)) def angle(v1, v2): return math.acos(dotproduct(v1, v2) / (length(v1) * length(v2))) Note : this will fail when the vectors have either the same or the opposite direction. The correct implementation is

How to calculate a bezier curve with only start and end points?

无人久伴 提交于 2019-12-14 02:52:05
问题 I originally posted a much simpler (and less helpful) question, and have edited this to be more specific. This animation from wikipedia shows basically what I want to accomplish, however - I'm hoping to have it flipped around, where it starts progressing more towards the destination and "up" (in this image), and then arcs more directly to the end point. However, I only have access to a starting point and ending point, what I am hoping to do is be able to determine the other points by

Calculating absolute differences between two angles

泄露秘密 提交于 2019-12-13 13:13:09
问题 I have two angles a and b, I want to calculate the absolute difference between both angles. Examples >> absDiffDeg(360,5) ans = 5 >> absDiffDeg(-5,5) ans = 10 >> absDiffDeg(5,-5) ans = 10 回答1: Normalize the difference, abs operation is not necessary because mod(x,y) takes the sign of y. normDeg = mod(a-b,360); This will be a number between 0-360, but we want the smallest angle which is between 0-180. Easiest way to get this is absDiffDeg = min(360-normDeg, normDeg); 回答2: When doing math with