psychopy.org | Reference | Downloads | Github

Is it possible to use ori(entation) attribute to rotate a line around its own center?

Dear,

In my experiment, each stimulus consists of three lines with different orientations.

For example, one left line could be rotated 5° degrees to the left, the middle and right line both 5° degrees to the right. Lines are defined like this:

#COORDINATES FOR PERFECTLY VERTICAL LINES#
#LEFT LINE#
ori_LL_LOW=[(-8.5,-294.47),(-8.5,-274.33)]

#CENTRAL LINE#
ori_CL_LOW=[(0,-294.47),(0,-274.33)]

#RIGHT LINE#
ori_RL_LOW=[(8.5,-294.47),(8.5,-274.33)]

left_line=visual.Line(window, units=‘pix’, start=ori_LL_LOW[0], end=ori_LL_LOW[1], ori=-5, lineColor=‘black’, lineWidth=1)
central_line=visual.Line(window, units=‘pix’, start=ori_CL_LOW[0], end=ori_CL_LOW[1], ori=5, lineColor=‘black’, lineWidth=1)
right_line=visual.Line(window, units=‘pix’, start=ori_RL_LOW[0], end=ori_RL_LOW[1], ori=5, lineColor=‘black’, lineWidth=1)

However, when I use the ori attribute in this way, then the horizontal alignment of my stimulus disappears, because it seems that all lines are rotated around the centre of the screen instead of around its own centre:
image

So, it want to draw a stimulus like this (which was done by changing the start and end positions manually):

image

Is this achievable by using the orientation attribute?

Thank you.

@Koen_Rummens, it looks like that the line stim rotates around the given position of your stim, rather than the centre point of your line. To actually achieve rotation around the centre point, you will have to do some calculations that 1) find the centre point of your line, 2) reposition to the centre point, 3) redraw lines relative to the new centre point. Maybe someone could let us know if there is a simpler way, but for now - In a code component and relevant tabs:

##### Start experiment
def midPoint(points):
    """Find midpoint of two points"""
    p1 = points[0]
    p2 = points[1]
    newp1 = round((p1[0]+p2[0])//2, 2)
    newp2 = round((p1[1]+p2[1])//2, 2)
    return (newp1, newp2)

ori_LL_LOW=[(-8.5,-294.47),(-8.5,-274.33)] # Your Left line variable

# Find midPoint using function
newPos = midPoint(ori_LL_LOW)

# Position and recalculate lines sizes in reference to new midpoint e.g., abs(y1-y2)/2 = +/-10.07
line = visual.Line(win, pos=newPos, start=(-0,-10.07), end=(0,10.07))

##### Every frame
line.ori = t*100  # Just to see rotation
line.draw()

Not sure if this is possible in your case, @Koen_Rummens, but could you perhaps use an image of a line and rotate this? (Or have images of lines with different orientations?)

Jan

1 Like

@jderrfuss, good idea. However, it is possible to change the orientation of the lines, you just need to draw the lines (i.e., set their start and end coordinates) relative to their position, such that the position is treated as a centre point. Position must be set explicitly when you create the visual.Line object. In the example code above, you do not need the extra function to find the centre point of the existing lines, you could just set the position of the lines and delete the function.

1 Like

Hi David. I used your code and defined a keyboard. But when the program checks for a keypress, the line stops rotating (I think it is the nature of for loops). Do you know what I should do so the line keeps rotating? Thanks.

# each frame tab

clock_hand.ori = t *140.23  # one rotation in 2560 ms
clock_hand.draw()

clock_key = event.getKeys(keyList = ["space","q"])
for thisKey in clock_key:
    if thisKey=='space':
        now = ptb.GetSecs()
        tone.play(when=now+0.1)  # play the tone for 0.1s
        continueRoutine= False
    elif thisKey == 'q':
        core.quit()