Coordinate comparison

OS (e.g. Win10): Win11 Pro
PsychoPy version (e.g. 1.84.x): 2021.2.3.
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I want to create some path (connected line from top to bottom of the screen), on which a spaceship (an image) comes down with some gravity and some variable drift forces to left and right. My participant should keep the spaceship as close as they can to the path. I also need to have the distance from the spaceship to the path, as a measure of the participant’s performance.

I welcome any suggestions to make this path/grid/connected dots/etc. whose coordinates I can have, with which I can compare the spaceship’s coordinates, at any frame.

Would gym environments work in PsychoPy?
Any suggestions on building this path? (at later stages, it needs to also be random for each participant)

Horizontal and vertical distance to the path should be fairly easy to save. Do you need direct distance to the closest point?

tTraceTest8 in my online demos has lines connecting random dots and Mouse tracking compares the distance of a mouse pointer to a target.

1 Like

If you upgrade to 2022.1.1, there’s a module in PsychoPy called layout which has some classes you’ll likely find useful - layout.Position creates an object which knows its position across various different spatial units. Multiple layout.Position objects can be added and subtracted from one another to do distance calculations irrespective of spatial units. In 2022.1.1 most visual objects (Polygon, Textbox, Image, etc.) also have an attribute ._pos which is the layout.Position object it uses to calculate its own position.

So you can get the distance between an object (let’s say it’s a visual.Image) and a point like so:

img = visual.Image(win, pos=(0.2, 0.3), units="height", etc.)
pos = layout.Position((-0.4, 0.5), "height", win)
distance = img._pos - pos

(this will be a layout.Position object whose x and y coords are the x and y distance between the two points)

1 Like

Thanks a lot @wakecarter, I made some changes to the target arrangement in your code to put the targets in a manner that the respective lines among them creates kind of a zigzag path, which can serve as the path that I need. I’ll reduce the number of them, to have a simpler path.

Is there a way that I can hold the shape with the connected lines in the end, so that in the next routine, my spaceship can run on them?

And I would need the distance of the spaceship to the line it’s closest to. That would be an orthogonal distance, right? How would that be possible?