## MinAreaRect angles – Unsure about the angle returned

I’m going to assume you’re using C++, but the answer should be the same if you’re using C or Python. The function minAreaRect seems to give angles ranging from -90 to 0 degrees, not including zero, so an interval of [-90, 0). The function gives -90 degrees if the rectangle it outputs isn’t rotated, i.e. … Read more

## Rotate a point by another point in 2D

If you rotate point (px, py) around point (ox, oy) by angle theta you’ll get: p’x = cos(theta) * (px-ox) – sin(theta) * (py-oy) + ox p’y = sin(theta) * (px-ox) + cos(theta) * (py-oy) + oy

## How to use 4d rotors

The most common way to represent goemetric algebra multivectors (including rotors) in a computer is via an array of coefficients, one for each canonical form algebra basis element (canonical basis blade) ie. for a 4D basis space you will have a 2^4 dimensional algebra and have 2^4 dimensional array of coefficients. An alternate but probably … Read more

## How can I find the smallest difference between two angles around a point?

This gives a signed angle for any angles: a = targetA – sourceA a = (a + 180) % 360 – 180 Beware in many languages the modulo operation returns a value with the same sign as the dividend (like C, C++, C#, JavaScript, full list here). This requires a custom mod function like so: … Read more

## Direct way of computing clockwise angle between 2 vectors

2D case Just like the dot product is proportional to the cosine of the angle, the determinant is proprortional to its sine. So you can compute the angle like this: dot = x1*x2 + y1*y2 # dot product between [x1, y1] and [x2, y2] det = x1*y2 – y1*x2 # determinant angle = atan2(det, dot) … Read more

## Rotating Image on A canvas in android

You can either rotate your bitmap when you draw it by using a matrix: Matrix matrix = new Matrix(); matrix.setRotate(angle, imageCenterX, imageCenterY); yourCanvas.drawBitmap(yourBitmap, matrix, null); You can also do it by rotating the canvas before drawing: yourCanvas.save(Canvas.MATRIX_SAVE_FLAG); //Saving the canvas and later restoring it so only this image will be rotated. yourCanvas.rotate(-angle); yourCanvas.drawBitmap(yourBitmap, left, top, … Read more

## Finding Signed Angle Between Vectors

What you want to use is often called the “perp dot product”, that is, find the vector perpendicular to one of the vectors, and then find the dot product with the other vector. if(a.x*b.y – a.y*b.x < 0) angle = -angle; You can also do this: angle = atan2( a.x*b.y – a.y*b.x, a.x*b.x + a.y*b.y … Read more

## How can I find the difference between two angles?

This gives a signed angle for any angles: a = targetA – sourceA a = (a + 180) % 360 – 180 Beware in many languages the modulo operation returns a value with the same sign as the dividend (like C, C++, C#, JavaScript, full list here). This requires a custom mod function like so: … Read more

## Angles between two n-dimensional vectors in Python

Note: all of the other answers here will fail if the two vectors have either the same direction (ex, (1, 0, 0), (1, 0, 0)) or opposite directions (ex, (-1, 0, 0), (1, 0, 0)). Here is a function which will correctly handle these cases: import numpy as np def unit_vector(vector): “”” Returns the unit … Read more

## How to know the angle between two vectors?

The tangent of the angle between two points is defined as delta y / delta x That is (y2 – y1)/(x2-x1). This means that math.atan2(dy, dx) give the angle between the two points assuming that you know the base axis that defines the co-ordinates. Your gun is assumed to be the (0, 0) point of … Read more