-1

Suppose we have a curve which is given by 3D points, for example:

(0.43, 0.55, 32.49), (0.61, 0.77, 31.24), (0.77, 1.01, 29.99), (0.88, 1.23, 28.75), (0.93, 1.41, 27.5), (0.91, 1.51, 26.25), (0.90, 1.59, 25), (0.81, 1.60, 23.75), (0.68, 1.58, 22.5), (0.46, 1.52, 21.25)

We try to figure out if there is a way to find the equation of the curve (it's coefficients and independent variable) by code in python, in a way that we can continue this curve to wherever we want? We had a few ideas to get the desired result by a projection to 2d with PCA and then taking a regression, but the result was poor

  • can you show what you've tried? – Nin17 Jul 21 '22 at 16:08
  • What is your actual question? What does it mean "in a way that we can continue this curve to wherever we want?" Just add one more point to the existing ones and then find the new polynom? – Claudio Jul 21 '22 at 16:15
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 21 '22 at 16:17

1 Answers1

0

One way is to fit two sets of coordinates independently with one axis as the base. You can find the polynomial coefficients in x_from_z and y_from_z.

One caveat though: This works for this example, but may not work for other coordinates. For other examples, you may have to play around with the axis, that you use as a base (only z worked in this case), and the degree of the polynom for the polyfit-function (3 worked, but 4 has a better fit in this case). In some cases it may not work at all.

import matplotlib.pyplot as plt
import numpy as np


points = [
    (0.43, 0.55, 32.49),
    (0.61, 0.77, 31.24),
    (0.77, 1.01, 29.99),
    (0.88, 1.23, 28.75),
    (0.93, 1.41, 27.5),
    (0.91, 1.51, 26.25),
    (0.90, 1.59, 25),
    (0.81, 1.60, 23.75),
    (0.68, 1.58, 22.5),
    (0.46, 1.52, 21.25)
    ]

x, y, z = zip(*points)

x_from_z = np.poly1d(np.polyfit(z, x, 4))
y_from_z = np.poly1d(np.polyfit(z, y, 4))

z_new = np.linspace(20, 35, 100)
x_new = x_from_z(z_new)
y_new = y_from_z(z_new)


fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(projection='3d')

ax.scatter(x, y, z)
ax.plot(x_new, y_new, z_new, c="k")

plt.xlabel("x")
plt.ylabel("y")

plt.show()

enter image description here

MangoNrFive
  • 1,541
  • 1
  • 10
  • 23