mdolab / pyspline

pySpline produces B-spline curves, surfaces, and volumes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Curve.projectCurve Not Finding Proper intersection

akleb opened this issue · comments

Description

When writing some unit tests for pyFoil I found that there seems to be a problem with the pySpline.Curve.projectCurve finding a proper intersection.

Steps to reproduce issue

See Code below list

  1. create a symmetric parabola looking curve with three coordinates
  2. use pySpline.Curve.splitCurve to split the curve into its two symmetric halves
  3. create a second curve that is vertical and intersects both halves
  4. use pySpline.Curve.projectCurve to determine the intersection of the two halves
  5. check the points and see that they are not the same points
import pyspline as pySpline
import numpy as np
import matplotlib.pyplot as plt 

coords = np.array([[1., 0.5], [0., 0.], [1., -0.5]])
vert_ray_coords = np.array([[0.05, 0.5], [0.05, -0.5]])

surf = pySpline.Curve(X=coords, k=3)
vert_ray = pySpline.Curve(X=vert_ray_coords, k=2)

top, bottom = surf.splitCurve(0.5)

s_top, t_top, d_top = top.projectCurve(vert_ray, eps=1e-16)
s_bottom, t_bottom, d_bottom = bottom.projectCurve(vert_ray, eps=1e-16)

print(top.getValue(s_top))
print(vert_ray.getValue(t_top))
print(d_top)
print(d_bottom)

top_intersect = top.getValue(s_top)
top_correct = top.getValue(1-s_bottom)
bottom_intersect = bottom.getValue(s_bottom)

s = np.linspace(0, 1, 200)
s2 = np.linspace(0, 1, 15) 

fig = plt.[mwe.pdf](https://github.com/mdolab/pyspline/files/6672752/mwe.pdf)()
plt.plot(surf.getValue(s)[:, 0], surf.getValue(s)[:, 1], label='total')
plt.plot(top.getValue(s)[:, 0], top.getValue(s)[:, 1], '--', label='top')
plt.plot(bottom.getValue(s)[:, 0], bottom.getValue(s)[:, 1], '--', label='bottom')
plt.plot(vert_ray.getValue(s)[:, 0], vert_ray.getValue(s)[:, 1], label='vert_ray')
plt.plot(top_intersect[0], top_intersect[1], 'o', label='top_intersect')
plt.plot(top_correct[0], top_correct[1], 'o', label='top_correct')
plt.plot(bottom_intersect[0], bottom_intersect[1], 'o', label='bottom_intersect')
plt.legend()
fig.savefig("mwe.pdf", bbox_inches='tight')

which produces
image

Current behavior

Check the figure, top_intersect is not at the intersection

Expected behavior

Check the figure, top_correct is where top_intersect should be