Skip to content

Fix incorrect coordinate transformation in spline#666

Open
Zhen-Ni wants to merge 1 commit intoFarama-Foundation:masterfrom
Zhen-Ni:fix-spline-coordinate-transformation
Open

Fix incorrect coordinate transformation in spline#666
Zhen-Ni wants to merge 1 commit intoFarama-Foundation:masterfrom
Zhen-Ni:fix-spline-coordinate-transformation

Conversation

@Zhen-Ni
Copy link
Copy Markdown
Contributor

@Zhen-Ni Zhen-Ni commented Mar 7, 2026

The coordinate transformation from Cartesian to Frenet in spline seems to have some incorrect output when the point is exactly on the spline. Here's the code for reproducing this issue:

spline = LinearSpline2D([(0, 0), (1, 0), (2, 0.5)])

# Find two very close points, the first is exactly lying on the
# spline, and the second is slightly offset by 0.0001
coor1 = spline.cartesian_to_frenet((1.5, 0.25))
coor2 = spline.cartesian_to_frenet((1.5, 0.25+0.0001))

# The following code prints (np.float64(1.5), np.float64(0.25)),
# which is incorrect as the lateral distance should be 0 (got 0.25 instead), because this point lies on the spline.
print(coor1)

# prints (np.float64(1.5590617157344975), np.float64(8.944271909994139e-05))
# A small deviation should not have such large error for lateral distance.
print(coor2)

This PR provides fix and optimization of the coordinate transform to solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant