1

I am stuck vector related problem.

I need to find a perpendicular vector(V) of fixed lentgh say 20 to other Normal vector(N) whose lentgh is unknown only direction.

for N and V I know intersecting co-ordinates. all this is happening in 3D space

After finding the perpendicular vector (V) I need to rotate that around every 15 degree to make a circle.

I want to do the thing shown in Image.

Algorithm Image (Point Signatures: A New Representation for 3D Object Recognition)

Complete article is here

Edit I have calculated new values on the basis of normal vector being

(0.121881, 0.572628, -1.636642)

I found unit vectors

a = (0.070118, 0.941570, 0.329436)

e = (0.070118, 0.329436, -0.941570)

vector t = (0.069774, 0.839384, 0.037374)

normalized t = b1 = (0.082758, 0.70769, 0.03151)

b2 = (0.676719, -0.080131, 0.022358)

and after plotting all that stuff it look something like [i.stack.imgur.com/0PGM0.png] , the selected red line is the normal to the surface.

  • You can take the vector $V$ that you are given, add to one of its components to get another vector $V_2$, then get a perpendicular vector by taking the cross product $V \times V_2$. – Carser Aug 10 '16 at 12:30
  • didn't get that., I'll add the image of what exactly I want. – Shahabaz Bagwan Aug 10 '16 at 12:35
  • Where's the image? When I have a single 3D basis vector, for which I need the two other basis vectors, and I don't have any external reference points/lines/vectors to refer to, I construct a helper vector by negating and permuting the components of the original vector (as opposed to adding to one of its components as Carser suggested), then orthonormalize it against the original vector. (As Carser mentioned, the final third basis vector is then just the cross product of the two first ones.) – Nominal Animal Aug 13 '16 at 18:08
  • I have added the image. thing is I know the Normal vector co-ordinate

    x = -0.068038 y = -0.0111010 z = 0.752

    I want to find the vector (n1) which will be perpendicular to (N) and having length 0.0002 units.

    Any idea how can I do that?

    – Shahabaz Bagwan Aug 15 '16 at 06:15
  • @NominalAnimal further details and the image is added, kindly check. – Shahabaz Bagwan Aug 15 '16 at 06:30
  • For input vector $(-0.068038, -0.0111010, 0.752)$, my answer gives $\vec{b}_3 = (-0.09009827, -0.01470033, 0.99582438)$ (parallel to the input vector, but length 1), and $\vec{b}_2 = (-0.99580494, -0.01469715, -0.09031347)$ (perpendicular to input vector, length 1). To get the vector $\vec{n}_1$ you mentioned, just scale $\vec{b}_2$ by $0.0002$. – Nominal Animal Aug 16 '16 at 14:33
  • @NominalAnimal thank you very much. – Shahabaz Bagwan Aug 17 '16 at 05:46
  • @NominalAnimal I guess I have given wrong Normal vector. correct values are, x = 0.121881, y = 0.572628, z= -1.636642.

    can you kindly provide me the values of b3 and b2 for this value.

    – Shahabaz Bagwan Aug 17 '16 at 06:12
  • For input vector $(0.121881, 0.572628, -1.636642)$, my answer gives the normalized basis vector parallel to the input vector as $\hat{e}_3 = (0.07011891, 0.32943650, -0.94157046)$, and the basis vector perpendicular to the input vector as $\hat{e}_2 = (0.06977500, 0.93996209, 0.33406992)$. (The last basis vector, also perpendicular to the input vector, is $\hat{e}_1 = \hat{e}_3 \times \hat{e}_2$.) – Nominal Animal Aug 17 '16 at 15:46
  • I ended up using dot product method for that. I projected the other vector whos distance I wanted and after that I used COS formula in regards to dot product to get the angle and the lenght of the projection. Thanks for the help. – Shahabaz Bagwan Aug 23 '16 at 05:41

2 Answers2

0

Let's say you have vector $\vec{n} = (x_n, y_n, z_n)$. (I like to use $\vec{v}$ for vectors, but $\hat{v}$ for unit vectors.)

The first basis vector is parallel to $\vec{n}$, but length 1. Because we only use this one to construct the two interesting basis vectors, I'll number this 3: $$\hat{e}_3 = (x_3, y_3, z_3) = \frac{\vec{n}}{\left\lVert\vec{n}\right\rVert}$$

We need an auxiliary vector which is not parallel to $\hat{e}_3$. If this auxiliary vector is also of unit length, the math in the following steps is simpler. There are many ways to construct one, but we need to be careful to not produce a vector too close to $\hat{e}_3$ (or its opposite!), or this approach will fail.

One interesting way to construct such $\hat{a}$ is to find out which two of the three components are largest in magnitude. Then, negate the largest in magnitude, and swap it with the second largest in magnitude. This yields an auxiliary vector at $70°$ to $90°$ angle to the basis vector, and keeps the vector length unchanged.

In pseudocode, this can be done as follows:

# Return an auxiliary vector, at 70 to 90 degree angle to
# the given vector, keeping length unchanged.
#
Function Auxiliary(x3, y3, z3):
    xm = abs(x3)
    ym = abs(y3)
    zm = abs(z3)

    If (xm >= ym), Then
        # |x3| >= |y3|
        If (ym >= zm), Then
            # |x3| >= |y3| >= |z3|
            xa =  y3
            ya = -x3
            za =  z3
        Else,
        If (xm >= zm), Then
            # |x3| >= |z3| > |y3|
            xa =  z3
            ya =  y3
            za = -x3
        Else,
            # |z3| > |x3| >= |y3|
            xa = -z3
            ya =  y3
            za =  x3
        End If
    Else,
        # |y| > |x|
        If (xm >= zm), Then
            # |y| > |x| >= |z|
            xa = -y3
            ya =  x3
            za =  z3
        Else,
        If (ym >= zm), Then
            # |y| >= |z| >= |x|, |y| > |x|
            xa =  x3
            ya =  z3
            za = -y3
        Else,
            # |z| > |y| > |x|
            xa =  x3
            ya = -z3
            za =  y3
        End If
    End If

    Return (xa, ya, za)
End Function

It does not actually matter how you construct $\hat{a}$, as long as it is not parallel to (or have a very small angle with) $\hat{e}_3$. The above is nice -- although it is very dense to read and maintain, hopefully it only needs to be written and tested thoroughly once! -- because it yields an "almost" perpendicular vector, no matter what the input vector, with just three absolute values, three comparisons, and assignments.

In any case, with $\hat{a}$ not parallel to $\hat{e}_3$ we can now easily construct a vector $\vec{t}$ perpendicular to $\hat{e}_3$: $$\vec{t} = \hat{a} - \hat{e}_3 \left ( \hat{a} \cdot \hat{e}_3 \right )$$ Because both vectors on the right side are of unit length, we don't need to divide by their lengths.

We have our first interesting basis vector if we normalize the perpendicular vector $\vec{t}$ to unit length: $$\hat{e}_1 = \frac{\vec{t}}{\left\lVert\vec{t}\right\rVert}$$

The final basis vector is simply a cross product of the two other unit basis vectors. Because the two are of unit length and perpendicular, the result will be perpendicular to both, and also of unit length: $$\hat{e}_2 = \hat{e}_3 \times \hat{e}_1$$

To generate $N$ points, $\vec{p}_1 \ldots \vec{p}_N$, at distance $r$ from $\vec{o}$, in a circle perpendicular to $\vec{n}$, use $$\vec{p}_i = \vec{o} + r \hat{e}_1 \cos\left(\frac{2 \pi i}{N}\right) + r \hat{e}_2 \sin\left(\frac{2 \pi i}{N}\right)$$ with either $i = 1\ldots N$ or $i = 0 \ldots N-1$.

  • Thank you for the help, I have done something in different manner like taking the normal vector, drawing a line along it and then finding the minimum distance of a point with that line. when I get the minimum distance between that point and the line I messure the distance between the 'point on the line which is closest to the given point' with the center of the sphere.

    I will add the image once I get back to home since all this is happening in 3d which can be hard to visualize.

    – Shahabaz Bagwan Aug 16 '16 at 11:46
  • @ShahabazBagwan: I don't exactly follow what you mean -- but I haven't had the time to read the article you linked to yet, so perhaps that is the reason. I did test (a C version of) the Auxiliary vector function -- with a few billion directionally uniformly distributed unit vectors (I like how good and fast the Xorshift family of PRNGs are) --, and it does indeed work as described (including result always having a 70 to 90 degree angle with the original vector); but that was about as much as I had time for. – Nominal Animal Aug 16 '16 at 14:08
  • Thank you, I can not understand what the "b3" is I mean is it "e3" and by mistake you wrote it as "b3"? – Shahabaz Bagwan Aug 17 '16 at 06:50
  • @ShahabazBagwan: Yes; I started with $\hat{b}$ basis vectors, but thought $\hat{e}$ would be better, but accidentally ended up not changing all. Edited to fix. – Nominal Animal Aug 17 '16 at 15:35
0

@Nominal-Animal's answer is probably right, but I wanted to warn you:

If you want the formula that generates the perpendicular vector to be continuous (e.g. give perpendiculars that are close to each other for the original vectors that are close to each other), then there is no solution.

You can easily create solutions that have 2 "special" points where the continuous perpendicular function turns zero vector (which is not perpendicular to anything). You can patch these points with some other non-zero perpendicular vector.

There can be a solution with only one "special point". Again, it can be patched, but the function won't be continuous at that point.

The fully continuous mapping is impossible. See Hairy ball theorem - Application to computer graphics

An example solution that has 2 special points:

The cross product of any two non-zero and non-collinear vectors is non-zero and perpendicular to both of those vectors. Thus, just take the cross product of your normal vector with some other constant vector e.g. $(0,0,1)$.

$\vec{N}(x,y,z) \times (0,0,1) = \vec{P_1}(y,-x,0)$.

For rotated vectors you'd need another perpendicular vector:

$\vec{N}(x,y,z) \times \vec{P_1}(y,-x,0) = \vec{P_2}(xz, yz, -x^2-y^2)$.

And finally here is the formula for the rotated vectors.

$\vec{p}_i = \vec{o} + r \frac{\vec{P_1}}{|\vec{P_1}|} \cos\left(\frac{2 \pi i}{n}\right) + r \frac{\vec{P_2}}{\vec{P_2}} \sin\left(\frac{2 \pi i}{n}\right)$ where $n$ is the number of rotated vectors you want (n = 24 for the angle of 15 degrees between vectors); $i$ is the rotated vector index which goes from $1$ to $n-1$.

P.S. As I mentioned, this formula fails for 2 special points/directions. In particular, for the normal vectors that only have a z coordinate non-zero $(0,0,z)$, you'd need to provide some special result answer.

Ark-kun
  • 256