Menu
  • HOME
  • TAGS

Math in programming: Trigonmetry about rotating angle between points

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); ...

How can i change the degree at which the gradient starts

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...

Calculate The object angle(face) having two points? [closed]

c++,math,geometry,angle

#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....

Get angle in terms of 360 degrees

javascript,circle,angle

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...

Libgdx rotating to angle with Vector2s

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,...

a method to find the nearest multiple of 2pi

c#,angle

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

data structure for storing angle intervals

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...

Convert Quaternion back into Euler

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...

Angle between two points, 0-360, CW? [closed]

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...

Reading a yaw navigation angle and set it to 0

rotation,angle,ar.drone

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

Calculating velocity from speed and direction

c++,sfml,trigonometry,angle

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); }...

WebGL: Asynchronous texImage2D?

webgl,angle

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.

How to calculate the angle of a trajectory without knowing the velocity

c#,math,unity3d,angle

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)...

Animating object angle to target angle

java,point,angle,animated

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...

Why does this angle calculation return only values of 0 or -1?

arduino,accelerometer,angle

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...

Getting the shortest angle path

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...

Defining an “inside room point” from wall points

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...

calculating angle between two points on edge of circle Swift SpriteKit

swift,circle,angle,degrees

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...

Orbital Mechanics: Estimated Time To Form Specific Angle Between Two Planets

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...

How do I draw a line at an angle?

java,swing,angle,jslider

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...

Racket GUI, drawing text vertically, issues with “angle” argument

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...

Python pendulum

python,physics,equation,angle

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: ")) ...

How do i orient my bullets in the right direction?

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...

Find the sign of the angles from an accelerometer

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...

How do I set a RevoluteJoint angle and velocity exactly?

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...

Find angle from two points formula

formula,angle,points

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...

Rotate a square by an angle in degree

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....

How to Determine the Angle of Rotation for a Point

algorithm,math,rotation,angle

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...

How do I generate a `x,y` co-ordinates that is always 90 degrees either left or to the right of the current position of a UIImage?

objective-c,math,angle

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....

Angular statistics doesn't make sense

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...

Rotation direction continuos check

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,...

How to get angle based on trigonometric function in C++

c++,trigonometry,angle

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...

Find a point on a line perpendicular and through the middle of another line

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....

how to make a bullet shoot diagonally in flash as3

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...

Angle between two lines beginning at one side of the line

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...

Find the angle of a rotated ellipse

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,...

How would i rotate a image on a canvas to face it's direction of movement?

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...

how to find angle between an ellipse and a vertical line that is in the middle of the image?

matlab,angle,ellipse

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...

ThreeJS : Line following mouse in 45 degrees

math,line,angle

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: find a x,y coordinate for a given point B using the distance from the point A (x0, y0) and the angle

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...

Objective-C Trigonometry

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...

Calculating angles between line segments (Python) with math.atan2

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...

How to convert an angle to a vector

java,math,vector,angle

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...