Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for projecting 3D spherical coordinates into 2D plane coordinates #12987

Open
sdsafsdfsaf opened this issue Nov 25, 2024 · 4 comments
Open

Comments

@sdsafsdfsaf
Copy link

locs3d -= sphere[:3]
 # use spherical (theta, pol) as (r, theta) for polar->cartesian
cart_coords = _cart_to_sph(locs3d)
out = _pol_to_cart(cart_coords[:, 1:][:, ::-1])
# scale from radians to mm
out *= cart_coords[:, [0]] / (np.pi / 2.0)
out += sphere[:2]
def _pol_to_cart(pol):
    """Transform polar coordinates to cartesian."""
    out = np.empty((len(pol), 2))
    if pol.shape[1] == 2:  # phi, theta
        out[:, 0] = pol[:, 0] * np.cos(pol[:, 1])
        out[:, 1] = pol[:, 0] * np.sin(pol[:, 1])
    else:  # radial distance, theta, phi
        d = pol[:, 0] * np.sin(pol[:, 2])
        out[:, 0] = d * np.cos(pol[:, 1])
        out[:, 1] = d * np.sin(pol[:, 1])
    return out

I cannot understand how the calculation formula for projecting condition 1 from 3D spherical coordinates to a two-dimensional plane is derived. Can you provide some references?

Copy link

welcome bot commented Nov 25, 2024

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴

@hoechenberger
Copy link
Member

hoechenberger commented Nov 26, 2024

Hi! I quickly copied your question into ChatGPT (model o1-preview)

See the response here:

https://chatgpt.com/share/67457e4f-3be0-800e-9737-293f51737d8d

(If the page doesn't load on the first try, click the link again)

@sdsafsdfsaf
Copy link
Author

Hi! I quickly copied your question into ChatGPT (model o1-preview)

See the response here:

https://chatgpt.com/share/67457e4f-3be0-800e-9737-293f51737d8d

(If the page doesn't load on the first try, click the link again)

Thank you, I have also inquired about chatgpt before, but after careful comparison, I found that the result was incorrect. This projection does not seem to simply take the original 3D coordinates of x and y, but rather performs a certain projection transformation on spherical coordinates, making the newly obtained x and y different from the original.

@hoechenberger
Copy link
Member

hoechenberger commented Nov 26, 2024

This projection does not seem to simply take the original 3D coordinates of x and y, but rather performs a certain projection transformation on spherical coordinates,

In the first step, the origin is shifted:

locs3d -= sphere[:3]

And after that, MNE converts the cartesian XYZ coordinates to polar corrdinates, and then projects those to the cartesian XY plane and scales the result. Maybe I'm misunderstanding your question 🤔

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

No branches or pull requests

2 participants