How do I project the X axis to a plane if the plane is defined by three points?
The default local 1-direction is the projection of the global x-axis onto the surface. If the global x-axis is within 0.1° of being normal to the surface, the local 1-direction is the projection of the global z-axis onto the surface.
Let's suppose that these points are:
t1 = [-0.362879991531372, 0.357021987438202, -0.373737007379532]
t2 = [-0.383525013923645, 0.371621012687683, -0.383549988269806]
t3 = [-0.383534014225006, 0.34629300236702, -0.38544899225235]
Is the vector [0.78280971952246, -0.0307519963686645, 0.411184845614438] correct answer in this case? I've calculated the angle between the surf and x (1,0,0) is ~28°.
And can you give the entire procedure for the calculation, because I'm just puzzled.
Your diagram is a little unclear (for instance, it doesn't show t1, t2, t3), but it looks as if you want a vector tangent to the surface and in the XZ plane. If that's correct, then you have to calculate the partial derivative with respect to x (the slope in the x direction, which is easy if the surface really is a plane and you have three non-colinear points) and the y-component of your answer will be zero. If that's not correct, then please explain what "projection" you prefer.
Related
I have asked a question similar to this before but have since got further and also didn't tag the question right and wanted to get a bit of help on the maths around the question if possible.
I have a 3D sphere with points evenly spaced on its surface of which I know the coordinates. From these coordinates I am trying to define the orientation of some spikes that are coming out of the surface of my sphere along the vector between the centre of the sphere and the point at which the coordinates lie.
The idea is these euler angles will be very helpful in later aligning the spikes so they are all in roughly the same orientation if I am am to box out all of the spikes from an image.
Since the coordinates on the sphere are evenly spaced i can just take the average x, y and z coordinates to give me the centre and I can then draw a vector from the centre to each coordinate in turn.
The euler angles I need to calculate in this case are initially around the z axis, then around the new y axis, and finally again around the new z axis.
My centre point is currently being defined as the average coordinate of all my coordinates. This works as the coordinates are evenly spaced around the sphere.
I then use the equation that states
cos(theta) = dot product of the two vectors / magnitude of each vector multiplied together
on the x and y axis. One of my vectors is the x and y of the vector i am interested in whilst the other is the y axis (0,1). This tells me the rotation around the z axis with the y axis being 0. I also calculate the gradient of the line on this 2D plane to calculate whether I am working between 0 and +180 or 0 and -180.
I then rotate the x axis about the angle just calculated to give me x' using a simple 2D rotation matrix.
I then calculate the angle in the same way above but this time around the y axis using x' and z' as my second vector (where z' = z).
Finally I repeat the same as stated above to calculate the new z'' and x'' and do my final calculation.
This gives me three angles but when I display in matlab using the quiver3 command I do not get the correct orientations using this method. I believe I just do not understand how to calculate euler angles correctly and am messing something up along the way.
I was hoping someone more knowledgeable than me could take a glance over my planned method of euler angle calculation and spot any flaws.
Thanks.
I Have the orthographic projection of a unit cube with one of its vertex at origin as shown above. I have the x,y (no z) co ordinates of the projections. I would like to compute the angle of rotation of the plane to get the second orthographic projection from the first one (maybe euler angles??)
Is there any other easy way to compute this?
UPDATE:
Could I use this rotation matrix to get a system of equations in cos, sin angles and the x,y and x',y' and solve them easily? Or is there any easier way to get the angles back? (Am I on the right direction to solve this? )
First method
Use this idea to generate equations:
a1, a2 and a3 are coordinates in the original system, x y are the coordinates you get from the end-result and z is a coordinate you don’t know. This generates 2 equations for every point of the cube. E.g for point 0 with coordinates (-1, -1, 1) these are:
Do this for the 4 front points of the cube and you get 8 equations. Now add the fact that this is a rotation matrix -> the determinant is 1 and you have 9 equations. Solve these with any of the usual algorithms for solving equation systems and you have the transformation matrix. Getting the axis and angle from that is easy via google: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/
Second method
Naming your points 0, 1, 2, 3 a, b, c, d respectively, you can get the z coordinates of the vectors between them (e.g. b-a) with this idea:
you will still have to sort out if b3-a3 is positive, though. One way to do that is to use the centermost point as b (calculate distance from the center for all points, use the one with the minimal distance). Then you know for sure that b3-a3 is positive (if z is positive towards you).
Now assume that a is (0,0,0) in your transformed space and you can calculate all the point positions by adding the appropriate vectors to that.
To get the rotation you use the fact that you know where b-a did point in your origin space (e.g. (1,0,0)). You get the rotation angle via dot product of b-a and (1,0,0) and the rotation axis via cross product between those vectors.
I am trying to quantize surface normals into let's say 8 bins.
For example, when computing features like HOG to quantize 2D gradients [x,y] into 8 bins we just take the angle with the y plane i.e. arctan(y/x) which will give us an angle between 0-360.
My question is, given a 3D direction [x,y,z], a surface normal in this case, how can we histogram it in a similar way? Do we just project onto one plane and use that angle i.e. the dot product of [x,y,z] and [0,1,0] for example?
Thanks
EDIT
I also read a paper recently where they quantized surface normals by measuring angles between normal and precomputed vectors that which are arranged around a right circular cone shape. I have added a link to this paper in the question (section 3.3.2 last paragraph), is this an effective approach? And if so, how do we compute these vectors?
Quantizing a continuous topological space corresponds to partitioning it and assigning labels to each partition. The straightforward standard approach for this scenario (quantizing normals) is as follows.
Choose your favorite uniform polyhedron:
http://en.wikipedia.org/wiki/Tetrahedron (4 faces)
http://en.wikipedia.org/wiki/Cube (6 faces)
http://en.wikipedia.org/wiki/Octahedron (8 faces)
http://en.wikipedia.org/wiki/Dodecahedron (12 faces)
http://en.wikipedia.org/wiki/Icosahedron (20 faces)
In general: http://en.wikipedia.org/wiki/Schl%C3%A4fli_symbol
Develop a mapping function from a normal on the unit sphere to the face of your chosen polyhedron that the normal intersects.
I would advise doing an argmax across polyhedron faces, taking the dot product of your normal and each polyhedron face normal. The one that gives the highest dot product is the face your normal should be binned into.
Use the face normal for each polyhedron face as the label for that face.
Prefer this approach to the approach suggested by others of mapping to spherical coordinates and then binning those. That approach suffers from too much sensitivity near the poles of the sphere.
Edit
In the paper you added to your question, the same idea is being used. There, however, the normals are restricted to a hemisphere - the only surfaces directly visible in an image have surface normals no more than 90 degrees away from the vector from the surface to the viewpoint.
The paper wants to quantize these surface normals into 8 values, represented by 8-bit integers with exactly one bit set to 1 and the rest set to 0. The 8 precomputed normals are computed as:
ntx = cos(a)*cos(t)
nty = cos(a)*sin(t)
ntz = sin(a)
where a = pi/4 and t = 0, pi/4, 2*pi/4, 3*pi/4, ..., 7*pi/4.
Notice
[cos(a)*cos(t)]2 + [cos(a)*sin(t)]2 + [sin(a)]2 = cos2(a)[cos2(t) + sin2(t)] + sin2(a) = cos2(a) + sin2(a) = 1
given a 3D direction [x,y,z], a surface normal in this case, how can
we histogram it in a similar way?
In the first case you quantize the polar orientation theta of the gradients. Now you need to quantize the spherical orientations theta and phi in a 2D histogram.
Do we just project onto one plane and use that angle
The binning of the sphere determines how you summarize the information to build a compact yet descriptive histogram.
Projecting the normal is not a good idea, if theta is more important than phi, just use more bins for theta
EDIT
Timothy Shields points in his comment and his answer that a regular binning of theta and phi won't produce a regular binning over the sphere as the bins will be bunched toward the poles.
His answer gives a solution. Alternatively, the non-regular binning described here can be hacked as follows:
Phi is quantized regularly in [0,pi]. For theta rather than quantizing the range [0,pi], the range [-1,1] is quantized instead;
For each quantized value u in [-1,1], theta is computed as
theta = arcsin(sqrt(1 - u * u)) * sign(u)
sign(u) returns -1 if u is negative, 1 otherwise.
The computed theta along with phi produce a regular quantization over the sphere.
To have an idea of the equation given above look at this article. It describes the situation in the context of random sampling though.
EDIT
In the above hack Timothy Shields points out that only the area of the bins is considered. The valence of the vertices (point of intersection of neighboring bins) won't be regular because of the poles singularity.
A hack for the previous hack would be to remesh the bins into a regular quadrilateral mesh and keep the regular area.
A heuristic to optimize this problem with the global constraints of having the same valence and the area can be inspired from Integer-Grid Maps Quad Meshing.
With the two hacks, this answer is too hacky and a little out of context as opposed to Timothy Shields answer.
A 3-dimensional normal cannot be quantized into a 1-D array as easily as for a 2-D normal (e.g., using arctan). I would recommend histogramming it into a 2-d space with a polar angle and an azimuth angle. For example, use spherical coordinates where the r (radius) value is always 1.0 (since your surface normal is normalized, length 1.0). In this case, you can throw away the r-value and just use polar angle θ (theta), and azimuthal angle φ (phi) to quantize the 3D normal.
Imagine you have a grid of sample points of a function z = f(x, y) where 1 < x < N and 1 < y < N. The formula is not given, but just the raw data, that could be for example the grey level of an image.
I would like to find, given a point A, whose x and y coordinates are given (and z is known from the data, so A is a vertex of the surface) a number M of points that lie on the circumference of the circle with center in A and radius R that are a good approximation of a circular "cloth" draped on the imaginary surface described by the data points. Imagine also that the edges of the surface are a triangle mesh.
The biggest constraint in the approximation is that the sum of the length of the edges of the resulting polygon is constantly R * 2 * PI, so that moving the A point across the surface would just change the M points but never the sum of their reciprocal distances. The draping doesn't need to be perfect, it would be nice though to be as close as possible to the surface., or always on one side of the surface, above or below.
Could anybody give me a pointer to something to read about this? Is this a known problem?
I feel that the problem is not completely formulated, I'd already like some help to give a complete description of it.
I'm doing something where I have a plane in a coord sys A with a set of points already on it. I also have a normal vector in space N. How can I rotate the points on coord sys A so that the underlying plane will have the same normal direction as N?
Wondering if any one has a good idea on how to do this. Thanks
If you have, or can easily compute, the normal vector to the plane that your points are currently in, I think the easiest way to do this will be to rotate around the axis common to the two planes. Here's how I'd go about it:
Let M be the vector normal to your current plane, and N be the vector normal to the plane you want to rotate into. If M == N you can stop now and leave the original points unchanged.
Calculate the rotation angle as
costheta = dot(M,N)/(norm(M)*norm(N))
Calculate the rotation axis as
axis = unitcross(M, N)
where unitcross is a function that performs the cross product and normalizes it to a unit vector, i.e. unitcross(a, b) = cross(a, b) / norm(cross(a, b)). As user1318499 pointed out in a comment, this step can cause an error if M == N, unless your implementation of unitcross returns (0,0,0) when a == b.
Compute the rotation matrix from the axis and angle as
c = costheta
s = sqrt(1-c*c)
C = 1-c
rmat = matrix([ x*x*C+c x*y*C-z*s x*z*C+y*s ],
[ y*x*C+z*s y*y*C+c y*z*C-x*s ]
[ z*x*C-y*s z*y*C+x*s z*z*C+c ])
where x, y, and z are the components of axis. This formula is described on Wikipedia.
For each point, compute its corresponding point on the new plane as
newpoint = dot(rmat, point)
where the function dot performs matrix multiplication.
This is not unique, of course; as mentioned in peterk's answer, there are an infinite number of possible rotations you could make that would transform the plane normal to M into the plane normal to N. This corresponds to the fact that, after you take the steps described above, you can then rotate the plane around N, and your points will be in different places while staying in the same plane. (In other words, each rotation you can make that satisfies your conditions corresponds to doing the procedure described above followed by another rotation around N.) But if you don't care where in the plane your points wind up, I think this rotation around the common axis is the simplest way to just get the points into the plane you want them in.
If you don't have M, but you do have the coordinates of the points in your starting plane relative to an origin in that plane, you can compute the starting normal vector from two points' positions x1 and x2 as
M = cross(x1, x2)
(you can also use unitcross here but it doesn't make any difference). If you have the points' coordinates relative to an origin that is not in the plane, you can still do it, but you'll need three points' positions:
M = cross(x3-x1, x3-x2)
A single vector (your normal - N) will not be enough. You will need another two vectors for the other two dimensions. (Imagine that your 3D space could still rotate/spin around the normal vector, and you need another 2 vectors to nail it down). Once you have the normal and another one on the plane, the 3rd one should be easy to find (left- or right-handed depending on your system).
Make sure all three are normalized (length of 1) and put them in a matrix; use that matrix to transform any point in your 3D space (use matrix multiplication). This should give you the new coordinates.
I'm thinking make a unit vector [0,0,1] and use the dot-product along two planes to find the angle of difference, and shift all your points by those angles. This is assuming you want the z-axis to align with the normal vector, else just use [1,0,0] or [0,1,0] for x and y respectively.