What is the "reference vector" in glm's orientedAngle() function? - c++

https://glm.g-truc.net/0.9.4/api/a00210.html
I'm trying to find the signed angle between two vectors in 3d space.
I can't seem to find what the "reference vector" is in this function, mathematically. Therefore, I don't know how to use the function. Thanks!

There is no such concept as signed angle between two vectors in 3D. If there is no any selected direction, you can get only angle in range 0..Pi (for example, using scalar product, that is invariant to argument order).
Imagine that you drew two vectors A and B (starting from one point) on a glass sheet. Look from one side of glass - you see that you need rotate A by 45 degrees to B. Look from another side - - you see that you need rotate A by -45 degrees to B.
If you have got some reference vector (axis), it helps to define orientation of plane that contains two vectors (positive normal direction), and you can determine also angle sign.
For example, sequence of vectors A, B, Ref may form 'right' oriented triplet (imagine 1st, 2nd, 3rd thumbs on the right hand), so you should turn vector A in positive direction to make it coinciding with vector B, around axis Ref (if Ref is perpendicular both A and B).
Or this sequence may be 'left' triplet, so you should turn vector A in negative direction to make it coinciding with vector B.
(Sorry for my ugly English)

Related

Axis of symmetry in cyclic graph

I have to write a program in c++ which returns the number of axis of symmetry in a cyclic graph.
A cyclic graph has an axis of symmetry when values between opposite vertices or edges on the left are a mirror image for values on the right.
The axis of symmetry may intersect both vertices and edges.
for example:
Is there any way to do this faster than O(n^2)?
n.m.’s answer is actually nearly correct, but not in any case.
Lets call one of the nodes the start node, and the axis, passing start node, the main axis.
Flipping a graph over some axis is equals to flipping it over main axis and rotation:
After rotation, main node can be placed on any other node place (and we also always can find current axis for doing this).
If we store our graph as a string, then flipped graph described by a reversed string cyclically shifted by 0 to N-1 positions.
Equality of those strings means the equality of the graphs. Obviously, number of such matches is equals to the number of occurs of reversed string in the twice repeated graph’s string:
So yes, KMP does the trick with O(N) complexity.
But you should avoid the case when str equals to reverse(str), because match will be counted with both 0 and N shifts, despite the fact they describe the same axis. So, you should use not concatenation of str and itself, but only first (2*N – 1) chars of this concatenation to achieve the proper behavior in any case.

How can I find the closest location on a map to an arbitrary point?

Note: For the remainder of this question I will call this arbitrary point as "myPoint" to avoid confusion.
Problem: There are several points on the map (it not practical to calculate the distance between each point and myPoint).
Attempt at a Solution: I tried doing a radius search but in order to know where these points are located within the circle, I would have to go through all the points and make sure the distance between them is less than the search circle's radius.
Question: How can I find the closest point to myPoint in an efficient way? Please ask questions if clarification is needed.
You could use a technique to "partition" the search space (i.e., the map).
You could consider defining a regular grid that covers the map and store all map locations within each cell of the grid.
With this it is easy to calculate/determine which cell contains the myPoint. Then it is just a matter of considering the points within the same cell.
Note: You may have to consider neighboring cells too in the event the cell containing myPoint doesn't have any map locations or that the distance to a point in a neighboring cell is shorter than the distance to the point within the same cell (e.g., myPoint is near a cell border).
Calculating the distance between the points is inevitable. What I suggest you can do is to slice the map in smaller pieces (not necessarily regular) and then only calculate the distance between the points that lie in the same slice.

How to compare relative rotation between objects?

I have two objects in 3D space (using OpenGL to render it all) of the same type of a class. These objects store xyz offsets and a rotation matrix representing your standard 4x4 rotational matrix.
A stripped down example:
class object {
float rotMatrix[16];
float xyzTrans[3];
//a displaylist for drawing the object
}
I'm using GLUI for UI controls which makes storing the transformations in format pretty simple.
The problem:
I need to define a "correct" orientation for one object with respect to the other. For example, if the first object is facing directly down the z-axis, and the second one is the same but also rotated roughly 45deg around the x-axis, this would be deemed "correct" and my functions do what they need to do. This can vary of course, maybe its the same z but rotated on the x and y, or maybe even rotated a little bit around each axis. The definition of "correct" rotations will be stored in the object for comparison.
Ideally I'm hoping to do something like:
bool checkRotation(object* first, object* second) {
//do some comparison stuff
if (eachCheck < someTolerance)
return true;
return false;
}
Is this possible to do by comparing two rotational matrices? Do I need to convert to quaternions and use those?
This question is the closest I've found to what I'm asking, but it's just different enough to be confusing.
Not a complete answer, but too long for a comment:
If you have two honest rotation matrices, then they should be invertible, and of determinant 1. Call the matrices A and B. If you want to check that the images A(X) and B(X) of the same object X under the two rotations is "close" in the sense that you can go from A(X) to B(X) by rotation around a specified axis, this is equivalent to checking whether the matrix obtained by taking A times the inverse of B is "nearly" a rotation around that axis. So this is probably the kind of thing you want to look at.
I'm not too familiar with the OpenGL matrix math functions so can't provide any code, sorry.

Partition an n-dimensional "square" space into cubes

right now I am stuck solving the following "semi"-mathematical Problem.
I would like to partition an n-dimensinal restricted space (a hypercube to be precise)
D={(x_1, ...,x_n), x_i \in IR and -limits<=x_i<=limits \forall i<=n} Into smaller cubes.
Meaning I would like to specify n,limits,m where m would be the number of partitions per side of the cube - 2*limits/m would be the length of the small cubes and I would get m^n such cubes.
Now I would like to return a vector of vectors containing some distinct coordinates of these small cubes. (or perhaps one could represent the cubes as objects which are characterized by a vector pointing to the "left" outer corner ? )
Basically I have no idea whether something like that is even doable using C++. Implementing this for fixed n does not pose a problem. But I would like to enable the user to have free choice of the dimension.
Background: Something like that would be priceless in optimization. Where one would partition the space into smaller ones and use e.g. a genetic algorithms on each of the subspaces and later compare the results. Thus huge initial Populations could be avoided and the search results drastically improved.
Also I am just curious whether sth. like that is doable :)
My Suggestion: Use B+ Trees ?
Let m be the number of partitions per dimension, i.e. per edge, of the hypercube D.
Then there are m^n different subspaces S of D, like you say. Let the subspaces S be uniquely represented by integer coordinates S=[y_1,y_2,...,y_n] where the y_i are integers in the range 1, ..., m. In Cartesian coordinates, then, S=(x_1,x_2,...,x_n) where Delta*(y_i-1)-limits <= x_i < Delta*y_i-limits, and Delta=2*limits/m.
The "left outer corner" or origin of S you were looking for is just the point corresponding to the smallest x_i, i.e. the point (Delta*(y_1-1)-limits, ..., Delta*(y_n-1)-limits). Instead of representing the different S by this point, it makes a lot more sense (and will be faster in a computer) to represent them using the integer coordinates above.

What does it mean to normalize a value?

I'm currently studying lighting in OpenGL, which utilizes a function in GLSL called normalize. According to OpenGL docs, it says that it "calculates the normalized product of two vectors". However, it still doesn't explain what "normalized" mean. I have tried look for what a normalized product is on Google, however I can't seem to find anything about it. Can anyone explain what normalizing means and provide a few example of a normalized value?
I think the confusion comes from the idea of normalizing "a value" as opposed to "a vector"; if you just think of a single number as a value, normalization doesn't make any sense. Normalization is only useful when applied to a vector.
A vector is a sequence of numbers; in 3D graphics it is usually a coordinate expressed as v = <x,y,z>.
Every vector has a magnitude or length, which can be found using Pythagora's theorem: |v| = sqrt(x^2 + y^2 + z^2) This is basically the length of a line from the origin <0,0,0> to the point expressed by the vector.
A vector is normal if its length is 1. That's it!
To normalize a vector means to change it so that it points in the same direction (think of that line from the origin) but its length is one.
The main reason we use normal vectors is to represent a direction; for example, if you are modeling a light source that is an infinite distance away, you can't give precise coordinates for it. But you can indicate where to find it from a particular point by using a normal vector.
It's a mathematical term and this link explains its meaning in quite simple terms:
Operations in 2D and 3D computer graphics are often performed using copies of vectors that have been normalized ie. converted to unit vectors... Normalizing a vector involves two steps:
calculate its length, then,
divide each of its (xy or xyz) components by its length...
It's something complicated to explain if you don't know too much about vectors or even vectorial algebra. (You can check this article about general concepts as vector, normal vector or even normalization procedure ) Check it
But the procedure or concept of "normalize" refers to the process of making something standard or “normal.”
In the case of vectors, let’s assume for the moment that a standard vector has a length of 1. To normalize a vector, therefore, is to take a vector of any length and, keeping it pointing in the same direction, change its length to 1, turning it into what is called a unit vector.