math,language-agnostic,geometry,angle

The atan2 function gives the angle of a point with respect to the X axis, given the point's x and y coordinates. The result typically ranges betwen -180 and 180 degrees, but we can adjust that to [0, 360] later. You can find the angle between two lines A and...

javascript,algorithm,math,point,angle

I'm going to propose a solution similar to David's, but using vertices rather than line segments. My solution also requires a consistent ordering of points, so I'll go with a clockwise ordering as well. The following pseudocode will generate an ordered listing (in the same order as that of the...

java,rotation,libgdx,angle,dot

When your ship is directly below, and just a little bit to the left of, the target, then the call Math.atan2(pTargetPos.x - pPos.x, -(pTargetPos.y - pPos.y)) will return a value very close to π/2. When your ship is directly below, and just a little to the right of, the target,...

current_yaw = read_yaw_angle() - initial_yaw; if (current_yaw < -180) { current_yaw += 360; } else if (currrent_yaw > 180) { current_yaw -= 360; } ...

The angle between the major axis of the ellipse and the x-axis is given by the Orientation property of regionprops. The angle is given in degrees and will lie in the range between -90° and +90°. I assume you are using exactly the mentioned code. There the Orientation value is...

Solution is to use texSubImage2D and upload image to GPU by small portions. Once uploading will be finished activate your new texture and delete old one.

return targetAngle + Math.Round((currentAngle - targetAngle)/(2*Math.Pi))*2*Math.Pi; ...

javascript,math,canvas,rotation,angle

You need to translate the canvas to the center point at which you will do the rotation Rotate based on the angle you have Draw image Reset transformation In code it would be these lines: ctx.translate(player.x, player.y); // translate to center of rotation ctx.rotate(angle + 0.5*Math.PI); // rotate, here...

You need to use a little bit more information than just the arcsin to figure this out. The reason for this is that arcsin will only return values between -π/2 and π/2 (-90 degrees and 90 degrees), as you already know. So, to figure out the other part, you need...

c++,rotation,angle,ellipse,dxf

You are ignoring the translation of the ellipse, that is, that the center may not be placed at (0, 0). If that where the case, your solution would be OK. To undo the effect of the translation, simply substract the coordinates for the center: auto angle = std::atan2(ellipse.my - ellipse.cy,...

physics,angle,orbit,orbital-mechanics

There is not a simple formula as such but there is an algorithm you could program to determine the results. Pentadecagon is also correct in that you need to take into account n*360. You are also right in that you stop one of the planets and work on the difference...

matlab,vector,3d,computational-geometry,angle

It's a simple use of the cross-product and scalar-product: You first find a normal vector N of the plane spanned by those points. This is done via the cross product of B-A and O-A. Then the directional vector AP can be found as the cross product of N and B-A....

python,coordinates,distance,trigonometry,angle

You just need a function that converts degrees to radians. Then your function simply becomes: from math import sin, cos, radians, pi def point_pos(x0, y0, d, theta): theta_rad = pi/2 - radians(theta) return x0 + d*cos(theta_rad), y0 + d*sin(theta_rad) (as you can see you mixed up sine and cosine in...

Besides the minor problems, like use of uninitialized variable here int y2 = y1 * y2;, You are using int variables for obviously floating point calculations of the angle, which should be a fractional number in radians (which is hinted by the calculation attempt used). You need to work with...

c#,math,vector,accelerometer,angle

I think you are confused about what you are actually calculating here. Make sure you are aware that you are simply calculating the angle by using the definition of cosinus: cos(accelAngleN*2*Math.Pi/360) = accelForceN/directionalVector (the multiplication with 2Pi/360 merely transforms an angle into Radian). Now consider that the angular sum in...

#include <cmath> // ... double angle = atan2(p2.y - p1.y, p2.x - p1.x); // ... If you want to, you can also make sure that p1 != p2, because if it is then you'll get a domain error....

I got the solution: float GetAngle(float height, Vector3 startLocation, Vector3 endLocation) { float range = Mathf.Sqrt(Mathf.Pow(startLocation.x - endLocation.x,2) + Mathf.Pow(startLocation.z - endLocation.z,2)); float offsetHeight = endLocation.y - startLocation.y; float g = -Physics.gravity.y; float verticalSpeed = Mathf.Sqrt(2 * gravity * height); float travelTime = Mathf.Sqrt(2 * (height - offsetHeight) / g)...

rotation,quaternions,euler-angles,angle

Figured it out, and appreciate your help antont. It was a nuance of Assimp. Apparently it for some odd reason (bug?) reads rotations in backwards, and so you have to do ToEulerZYX, but then reverse use of xyz to zyx. float3 keyValueOrig = quat.ToEulerZYX(); float3 keyValue; keyValue.z = RadToDeg(keyValueOrig.x); keyValue.y...

statistics,mean,angle,direction

The values don't look right Angles that differ by 360 are equivalent. So, -28.8551147 == 331.145, which is the arithmetic mean of the two values you provided. If you would like to ensure that your values are always in [0,360), you should add 360 if the values are less...

Given points p1, p2 on a circle with center center, you would compute the difference vectors first: let v1 = CGVector(dx: p1.x - center.x, dy: p1.y - center.y) let v2 = CGVector(dx: p2.x - center.x, dy: p2.y - center.y) Then let angle = atan2(v2.dy, v2.dx) - atan2(v1.dy, v1.dx) is the...

tan, sin, and cos are actually measuring the ratios between two edges of a 3-edged object aka a triangle. Hence in your case, to form that triangle, you will need the lengths of two edges. They are the lengths between y1 and y2, and x1 and x2. That is why...

ios,objective-c,gradient,layer,angle

Here is some code I've patched into the angleGradient(...) function in AngleGradientLayer.m. float offset = M_PI / 4; float angle = atan2f(dirY, dirX) + offset; while (angle < 0) angle += 2 * M_PI; while (angle > 2 * M_PI) angle -= 2 * M_PI; while (angle < 0) angle...

objective-c,math,trigonometry,angle

The trig formula is tan(angle) = opposite / adjacent So to get the angle from the side lengths, you need to use the inverse tangent, which is atan2. double angle = atan2(opposite, adjacent); From there the rest of your code works as long as you know that atan2 returns an...

I think one way would be something like ... dAngle = (targetAngle - angle) % two_pi; //Range of (-two_pi .. two_pi) dAngle += (dAngle > pi? -two_pi : dAngle < -pi? two_pi : 0); //Range of [-pi .. pi] angle += 0.05 * dAngle; Also, if you want it always...

Polar coordinate system As everybody seems to have just answered in the comments, here goes the answer to your question as it is formulated : you need to use the polar coordinate system. Let's call your angle a, the angle you want to add to it b, so the modified...

actionscript-3,flash,angle,diagonal

There's a good example of this at:- http://rhuno.com/flashblog/2011/11/18/calculating-angles-and-moving-objects-accordingly/ You want to do something like var angle:int = 270; var rads:Number = angle*Math.PI/180; var speed:int = 2; function moveBullet(e:Event) { e.currentTarget.x += Math.cos(rads) * speed; e.currentTarget.y += Math.sin(rads) * speed; } You'll need to set angle accordingly depending on which way...

android,math,trigonometry,angle

If you want to find angle between vectors (point-previous) and (point-now), use: Math.atan2((now.x - point.x)*(previous.y - point.y) - (now.y - point.y)*(previous.x - point.x), (now.x - point.x)*(now.y - point.y) - (previous.x - point.x)*(previous.y - point.y)) (This is atan2(vectorproduct, scalarproduct)) You may also use angle = atan2(now.y-point.y, now.y-point.y)- atan2(previous.y-point.y, previous.x-point.x); ...

user-interface,text,racket,angle

It's not clear from the example, but did you remember to convert the 90 degrees into radians? The convention is that 360 degrees is the same as 2pi radians. Or dividing by 360, we get that 1 degree is 2pi/360 radians. Multiplying by 90, the result is that 90 degrees...

algorithm,binary-search-tree,computational-geometry,intervals,angle

The circularity of angles is not a major obstacle: to instead an interval like [270, 45) that wraps around, instead insert two intervals [270, 360), [0, 45). To implement insertion without wraparound, we can use a binary search tree. This tree tracks the uncovered intervals by mapping each endpoint of...

matrix,rotation,processing,game-physics,angle

If you want to get an angle between 2 points you can use atan2 the following way: angle = atan2(playerY - bulletY, playerX - bulletX); //This angle is not returned in radians, to convert it simply use the function: angle = degrees(angle); Of course afterwards you have to draw the...

I forgot to convert the angle back to radians -.-" The following code fixes my issue. Line is now drawn with an angle with degree 0, 45, 90, 135, 180.. etc if (l_vIsCtrlPressed) { var length = Algo.Length(p1, p2); var angle = Algo.Angle(p1, p2); angle = Algo.ConvertToDegrees(angle); angle = Math.round(angle...

python,trigonometry,angle,atan2,cartesian-coordinates

The easiest and most logically way to get at this problem is using the dot-product. Try this code (I've commented practically everything): import math def dot(vA, vB): return vA[0]*vB[0]+vA[1]*vB[1] def ang(lineA, lineB): # Get nicer vector form vA = [(lineA[0][0]-lineA[1][0]), (lineA[0][1]-lineA[1][1])] vB = [(lineB[0][0]-lineB[1][0]), (lineB[0][1]-lineB[1][1])] # Get dot prod dot_prod...

Try this: Convert your CGPoint to a vector then use: /* * Returns the vector rotated by an angle */ - (CGVector)vectorFromVector:(CGVector)vector rotatetByAngle:(CGFloat)radians{ return CGVectorMake(cosf(radians) * vector.dx - sinf(radians) * vector.dy, sinf(radians) * vector.dx + cosf(radians) * vector.dy); } and convert back to CGPoint....

python,rotation,computational-geometry,angle

It's such a simple thing -- you've got the formula wrong for all of your y-values. It should be: ya_new = sin(theta) * (xa - x) + cos(theta) * (ya - y) + y addition instead of subtraction....

c#,actionscript-3,angle,difference

Maybe this helps. The variable continuousAngle will track the total knob turning performed, i.e. turning the knob twice counterclockwise will get you to 720. Then turning it three times clockwise takes you back down to -360. Everything else should be easy to derive - limiting the minimum and maximum values,...

Well, the sin of this angle is [a, b] / (abs(a) * abs(b)) and its cos is (a, b) / (abs(a) * abs(b)), where [a, b] is a cross product of a and b, (a, b) is a scalar product and abs(x) is the length of the vector x. It...

Use the function angle = atan2(y, x) Here's a link to more info: http://www.cplusplus.com/reference/cmath/atan2/ OR http://en.cppreference.com/w/cpp/numeric/math/atan2...

box2d,angle,jbox2d,revolute-joints

Joints don't inherently have any angle or velocity of their own. It's the relative angle and velocity of the two bodies they connect that determines what you get when you call GetJointAngle and GetJointSpeed (see the source). So it follows that there is so direct means to set these things...

math,geometry,line,pseudocode,angle

Let's define some notation: A := (a1, a1). B := (b1, b2). C := (c1, c2). Then the determinant D of the matrix 1 a1 a2 1 b1 b2 1 c1 c2 determines whether C lies left or right of the directed line AB [cf. Computational Geometry - Berg, van...

Taking k_g's answer, we can actually shorten it quite a bit given that Vector2f has operator overloads. It can simply become: sf::Vector2f findVel(const sf::Vector2f& aPos, const sf::Vector2f& bPos, float speed) { sf::Vector2f disp = bPos-aPos; float distance = sqrt(disp.x*disp.x+disp.y*disp.y); // std::hypot(disp.x, disp.y) if C++ 11 return disp * (speed/distance); }...

For any physically-reasonable pendulum, your h should be less than 1 (seconds) to model this properly. But you're casting to int which rounds down, so you get h=0 (no time step). Instead, use float: h=float(input("h: ")) q=float(input("Angle: ")) l=float(input("Pendulum length: ")) ...

Step 1: Extend JPanel and override paintComponent(). You've mentioned you already do this step, but more info is available here. Step 2: Get the value of your JSlider into your paintComponent() method. Step 3: Add a listener to the JSlider that tells your JPanel to repaint itself whenever the value...

math,geometry,shortest-path,angle,smallbasic

Surely that's just setting the direction based on which angle you choose. If you're working out the angle/direction from a1 to a2, the following pseudo-code should give you what you need: # precondition: [a1,a2] >= 0 angle = ((a2 % 360) - (a1 % 360) + 360) % 360 direction...