I have been working on this problem for a few days already, but could not figure it out completely.
Let's assume that I have two points, pointO (0,0,0) and pointA (1,1,1). Then we can calculate the vector of OA = <1,1,1>
I have a circle on the X-Y plane and the coordinates I derived is from X_circle = radius * cos(theta) Y_circle = radius * cos(theta) Z_circle = 0
Based on these circle coordinates (x,y,z), I want to project/translate it so that the circle is perpendicular to the vector OA.
I have followed this as my reference to this problem. However, my Z-coordinates are not translated. Where did I miss? Any feedback would be greatly appreciated.
I also provide my code for this problem. Please refer below.
def vector(point0, point1):
return np.array((point1[0]-point0[0], point1[1]-point0[1], point1[2]-point0[2]))
def magnitude(vec):
return np.array(math.sqrt((vec[0]**2+vec[1]**2+vec[2]**2)))
def unit_vector(vec, mag):
return np.array(vec/mag)
# convert points into list of coordinates x, y, z
def conv_point_list(point):
x_list.append(point[0])
y_list.append(point[1])
z_list.append(point[2])
point0 = [0,0,0]
point1 = [1,1,1]
vec = vector(point0, point1)
print(vec)
mag = magnitude(vec)
print(mag)
uvec = unit_vector(vec, mag)
print(uvec)
# put to a list
x_list = []
y_list = []
z_list = []
conv_point_list(point0)
conv_point_list(point1)
# Plot a circle on a 2D plane
angle = np.linspace( 0 , 2 * np.pi , 150 )
radius = 0.4
# circle data points [r*cos(theta), r*sin(theta), 0]
x_circle = radius * np.cos( angle ) # r*cos(theta)
y_circle = radius * np.sin( angle ) # r*sin(theta)
z_circle = np.zeros(150)
# Translation
x_circle_t = np.multiply(RxRy[0], x_circle)
y_circle_t = np.multiply(RxRy[1], y_circle)
z_circle_t = np.multiply(RxRy[2], z_circle)
# Import libraries
# https://pythonguides.com/matplotlib-3d-scatter/
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
import plotly.graph_objects as go
# Create Figure
fig = plt.figure(figsize = (10, 7))
ax = plt.axes(projection ="3d")
# Create Plot
ax.scatter3D(x_list, y_list, z_list, marker='o', s=20, label='points', c='r')
ax.plot(x_list, y_list, z_list) # vector
# Plot a circle on a 2D plane
ax.plot(x_circle, y_circle, z_circle, c='green', label='circumference')
ax.plot(x_circle_t, y_circle_t, z_circle_t, c='orange', label='circumference_T')
# Parameters
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# Add legend
ax.legend(loc=1)
# Show plot
plt.show()
If $\omega = \frac{OA}{\|OA\|}$ is a unitary vector and $v_0$ is a vector orthogonal to $\omega$, you can parametrize the circle centered on $(0,0,0)$ passing through $v_0$ in a plane orthogonal to $\omega$ by the formula \begin{equation} v(t) = \cos(t) v_0 + \sin(t) \omega\times v_0 \end{equation}
In your case, if $r$ is the radius of the circle, one can choose $v_0 = \frac{r}{\sqrt{2}}(1, -1, 0)^T$ and we have $\omega = \frac{1}{\sqrt{3}}(1, 1, 1)^T$. It follows that \begin{equation} v(t) = \frac{r}{\sqrt{6}}\begin{bmatrix} \sqrt{3}\cos(t)+ \sin(t)\\ -\sqrt{3}\cos(t)+ \sin(t)\\ -2\sin(t) \end{bmatrix} \end{equation} It is easy to check that $\|v(t)\| = r$ and $x(t)+ y(t)+z(t) = 0$.