Joe - 7 months ago 72

Vb.net Question

I have a straight line in space with an start and end point (x,y,z) and I am attempting to get the angle between this vector and the plane defined by

`z=0`

Here is a picture of the line in my 3d environment (the line I'm intersted in is circled in red) :

It is set to an angle of 70 degrees right now.

Answer

You need 2 rays to define an angle.

If you want the angle between a vector and a plane, it is defined for any vector in that plane. However, there is only one minimal value for that, which is the angle between a vector and its projection onto said plane.

Therefore, that minimal value is the one we take when we speak of the angle between a vector and a plane.

This value is also π/2 - the angle between your vector and the the vector that is normal to the plane.You can read more about it all on this site.

With `v`

your vector (thus `v.x = end.x - start.x`

and idem for `y`

and `z`

), `n`

the normal to the plane and `a`

the angle you are looking for, we know from the definition of a scalar product that:

```
<v,n> = ||v|| * ||n|| * cos(π/2 - a)
```

We know `cos(π/2 - a) = sin(a)`

, and the normal to the `z=0`

plane is simply the vector `n = (0, 0, 1)`

. Thus both the scalar product, `v.x * n.x + v.y * n.y + v.z * n.z`

, and the norm of n, `||n|| = 1`

, can be simplified a lot. We get the following expression:

```
sin(a) = v.z / ||v||
```

Thus finally, the formula by taking the reciprocical of the sine and expliciting the norm of `v`

:

```
a = Asin(v.z / sqrt( v.x*v.x + v.y*v.y + v.z*v.z ))
```

According to this documentation the `Asin`

function exists in your System.Math class. It does, however, return the value in radians:

Return Value Type: System.Double An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2 -or- NaN if d < -1 or d > 1 or d equals NaN.

Luckily the same System.Math class contains the value of π so that you can do the conversion:

```
a *= 180 / Math.PI
```