```python
import numpy as np
from skspatial.objects import plane
from sympy import Plane

def perpendicular(a):
    b = np.empty_like(a)
    b[0] = -a[1]
    b[1] = a[0]
    return b


def normalize(a):
    a = np.array(a)
    return a/np.linalg.norm(a)


def get2DProjection(origin, target_point):
    points = [origin,
              target_point,
              [target_point[0], target_point[1], target_point[2] + 1]]  # add 1 in order not to be collinear

    plane = Plane(points[0], points[1], points[2])
    plane_normal = np.array(plane.normal_vector)

    target_point, origin = np.array(target_point), np.array(origin)

    x_axis = normalize(np.array([target_point[0], target_point[1], 0]))
    y_axis = normalize(np.array([0, 0, 1]))

    s = np.dot(plane_normal, target_point-origin)
    x_coord = np.dot(x_axis, target_point-origin)
    y_coord = np.dot(y_axis, target_point-origin)

    return s, x_coord, y_coord


if __name__ == "__main__":
    target_point = [2, 2, 1]
    origin = [0, 0, 0]
    s, t_1, t_2 = get2DProjection(target_point, origin)

    print("s:", s)
    print("t_1:", t_1)
    print("t_2:", t_2)
```

    s: 0
    t_1: nan
    t_2: -1.0


    /var/folders/sd/1vc_q83x5rn9jjrd0x47_cc00000gn/T/ipykernel_92659/4172601782.py:14: RuntimeWarning: invalid value encountered in true_divide
      return a/np.linalg.norm(a)



```python

```

f229c8bdc4ddbc1736dec3d9774de79ae7b91f50
ipynb
Jupyter Notebook
Mathematics/Linear Algebra/Python Visualization Notebooks/scikit-spatial/Projecting-3D-points-to-2D-plane.ipynb
okara83/Becoming-a-Data-Scientist
f09a15f7f239b96b77a2f080c403b2f3e95c9650
MIT
Mathematics/Linear Algebra/Python Visualization Notebooks/scikit-spatial/Projecting-3D-points-to-2D-plane.ipynb
okara83/Becoming-a-Data-Scientist
f09a15f7f239b96b77a2f080c403b2f3e95c9650
MIT
Mathematics/Linear Algebra/Python Visualization Notebooks/scikit-spatial/Projecting-3D-points-to-2D-plane.ipynb
okara83/Becoming-a-Data-Scientist
f09a15f7f239b96b77a2f080c403b2f3e95c9650
MIT
2022-02-09T15:41:33.000Z
2022-02-11T07:47:40.000Z
Qwen/Qwen-72B
1. YES
2. YES