How can I create a circle facing a vector in 3 dimensional space?

967 Views Asked by At

I am trying to create a circle in 3D space, and all I have is a vector from Point A to Point B, and a radius. The center point of this circle can be any point along the line A to B, but the circle needs to face in the direction of the vector.

Now, I understand how to make a circle in 2D space; x = radius * cos(angle); y = radius * sin(angle), but the third dimension really begins to confuse me. I took to geogebra to see if I could figure out how to do it, and while I've managed to get the result I want, I can't understand how the values from its predefined Circle function are created. Here's an image of my desired result. What I don't understand is how 1.41, 0.82 and 1.63 are obtained.

I've tried to find resources to help me with this specific problem online but have not got very far and would appreciate some help.

enter image description here

2

There are 2 best solutions below

0
On

Given a normal direction to the circle, in which slides the center, and a radius, we can build a circle as follows. First, assuming the center point is at $c = \frac 12(A+B)$ and with $\vec n = \frac{A-B}{\|A-B\|}$ we construct a orthonormal basis centered at $c$ with $\{\vec u, \ \vec v,\ \vec n\}$ such that $\vec u\times\vec v = \vec n$ and then we have the circle with radius $r$ as

$$ \mathcal{C}(\theta) = c + r\vec u\cos\theta + r\vec v\sin\theta $$

NOTE

To choose $\vec u$ given $\vec n$ we solve

$$ \cases{ u_xn_x+u_yn_y+u_zn_z=0\\ u_x^2+u_y^2+u_z^2 = 1 } $$

0
On

Another way of doing this. We will start with a circle on the x-y plane and then rotate, and translate it to be the required circle.

Let the circle be on the x-y plane. Then, the points of the circle can be represented as $[rcos(\theta),rsin(\theta),0]$. Now you want to rotate the z-axis to point to the required vector v. Ensure v is scaled to be of unit norm. We will rotate the space along the X and Y axes to point along v (rotation along z is not required)

The rotation matrix $R_X(\alpha) = \begin{bmatrix} 1 & 0 & 0\\ 0 & cos(\alpha) & -sin(\alpha)\\ 0 & sin(\alpha) & cos(\alpha)\\ \end{bmatrix}$ and $R_Y(\beta) = \begin{bmatrix} cos(\beta) & 0 & sin(\beta)\\ 0 & 1 & 0\\ -sin(\beta) & 0 & cos(\beta)\\ \end{bmatrix}$

We want

$R_X(\alpha)\cdot R_Y(\beta) \cdot z = v$

$$\begin{eqnarray} R_X(\alpha)\cdot R_Y(\beta) \cdot z &=& v \nonumber \\ \begin{bmatrix} 1 & 0 & 0\\ 0 & cos(\alpha) & -sin(\alpha)\\ 0 & sin(\alpha) & cos(\alpha) \end{bmatrix}\cdot \begin{bmatrix} cos(\beta) & 0 & sin(\beta)\\ 0 & 1 & 0\\ -sin(\beta) & 0 & cos(\beta)\\ \end{bmatrix} \cdot \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix} &=& v \nonumber \\\\ R_{X,Y}(\alpha,\beta) \cdot z &=& v \nonumber \\ \begin{bmatrix} cos(\beta) & 0 & sin(\beta)\\ sin(\alpha)sin(\beta) & cos(\alpha) & -sin(\alpha)cos(\beta)\\ -cos(\alpha)sin(\beta) & sin(\alpha) & cos(\alpha)cos(\beta)\\ \end{bmatrix} \cdot \begin{bmatrix} 0\\ 0\\ 1 \end{bmatrix} &=& v \nonumber \\\\ \begin{bmatrix} sin(\beta)\\ -sin(\alpha)cos(\beta)\\ cos(\alpha)cos(\beta) \end{bmatrix} &=& v \end{eqnarray}$$

Thus we have $v_1 = sin(\beta)$, $cos(\beta) = \sqrt{1-v_1^2}$ and thus $sin(\alpha) = \dfrac{v_2}{\sqrt{1-v_1^2}}$, with the appropriate signs.

Finally, we translate the circle from $[0,0,0]$ to the point O $[o_1,o_2,o_3]$. Thus our final equation looks as follows $$C \equiv O + R_{X,Y}(\alpha, \beta)[rcos(\theta),rsin(\theta),0]$$

A particular software design choice may choose the initial circle along a different plane (other than X-Y), and thereby, the rotations would also be different.


In your case, $v =\left [\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}}\right]$, $r=2$, $O = [0.44,0.44,0.44]$.

Then we have $cos(\beta) = \sqrt{1-\frac{1}{v_1^2}} = \sqrt{1-\frac{1}{3}}$ Therefore, $cos(\beta) = \sqrt{\frac{2}{3}} = 0.81634 \sim 0.82$

$sin(\alpha) = \frac{v_2}{\sqrt{1-v_1^2}} = \frac{1}{\sqrt{2}} \sim 0.7071$. Then, $cos(\alpha) = \frac{1}{\sqrt{2}} \sim 0.7071$. Choosing an appropriately oriented initial circle and rotations would lead you to the parametrizations in geogebra.