<jupyter_start><jupyter_text>2D curve self-intersections<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from skcurve.curves import lissajous
from skcurve.plot import curveplot<jupyter_output><empty_output><jupyter_text>Create 2D curve objectWe use non-closed "lissajous" curve to demonstrate self intersecting.<jupyter_code>crv = lissajous(t_start=-0.045, t_stop=np.pi*2-0.045, p_count=1000, a=8.0, b=7.0)[1:]

print(crv)<jupyter_output>Curve([[-0.3048 -0.2677]
       [-0.2565 -0.225 ]
       [-0.2075 -0.1819]
       [-0.1581 -0.1384]
       ...
       [-0.489  -0.4323]
       [-0.4445 -0.3922]
       [-0.3989 -0.3514]
       [-0.3523 -0.3098]], size=999, ndim=2, dtype=float64)<jupyter_text>Find self-intersectionsWe just call `intersect` method of `Curve` object.<jupyter_code>%%time
intersections = crv.intersect()

print(f'The number of intersections: {len(intersections)}')<jupyter_output>The number of intersections: 97
Wall time: 276 ms<jupyter_text>Plot curve and intersection pointsWe use `curveplot` to plot the curve and intersection points.<jupyter_code>f, ax = plt.subplots(1, 1, figsize=(9, 7))

curveplot(crv, axes=ax)

start, end = crv[0], crv[-1]

ax.scatter([start[0]], [start[1]], color='r', marker='.')
ax.scatter([end[0]], [end[1]], color='b', marker='.')

intsct_px = [] 
intsct_py = []

for n, intersection in enumerate(intersections, start=1):
    p = intersection.intersect_point
    intsct_px.append(p[0])    
    intsct_py.append(p[1])

ax.scatter(intsct_px, intsct_py, edgecolor='k', facecolor='r', zorder=3)

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16, 'fraction_numerical': 0.076875, 'mean_word_length': 4.637323943661972, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '372609', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 702, 'n_tokens_neox': 635, 'n_words': 126, 'path': 'examples/curve_self_intersections.ipynb', 'repo_name': 'espdev/scikit-curve', 'size': '1600'}