Creating angle from lineStim with random orientation around the center of the screen


My goal is make an experiment in which an 90 deg angle is shown in the center of the center of the screen with random orientation.


If position of line is (0,0) its` center is located at the center of the monitor. Since the angle should appear at the center the position stimuli should be changed with each orientation.

An orientation of the first line is random and an orientation of the second line ±90deg relative to the first line’s orientation.

To control position the lines should be offset from the centre of the screen by half its length at the same angle. So, xpos = cos(x)*length/2, ypos = sin(x)*length/2, where x is orientation in radians.

However, I have a problem, and I can’t figure out where I made a mistake. In my experiment lines are shown with 90 deg relative orientation between each other, but they do not meet in the center of the screen and form an angle. (See screenshots)

I use builder with additional code component
Here is my code:

Before experiment:
mywin = visual.Window([1280,720],monitor=“testMonitor”, units=“deg”)
line1= visual.Line(mywin, start=(0,0)) #I tried to set up the start of both lines at the center of the screen in coder, but it didn`t work out
line2= visual.Line(mywin, start=(0,0))


Begin routine:
#seting up relative 90 deg orientation between lines
orient1 = random.randint(0,360) #orientation of the first line
ops= (add, sub)
op = random.choice(ops)
orient2 = op(orient1, corner) #orientation of the second line

#seting up position of line
x1=np.radians(orient1) #changing to radians

#the line length is 7 so sin and cos are multiplied by 3.5
pos1=( cos(x1)*3.5, sin(x1)*3.5) #position of the first line
pos2=( cos(x2)*3.5, sin(x2)*3.5) #position of the second line

I would be very grateful for your help.

While I do love a good trig problem, I think in your case you would be better off using a custom polygon with vertices: [[-3.5,3.5],[-3.5,-3.5],[3.5,-3.5],[-3.5,-3.5]]

Thanks for your suggestion!

I still seem to have a problem with positioning the angular stimulus in the center of the screen after using the custom polygon. I’ve tried using different anchor and position settings (custom 0,0 and my custom code with sin and cos orientation), but it still doesn’t appear in the center of the screen.

Also, now I have a problem with the dimensions and units. I need the corner to have 7 cm, but if I use the size (7.7) in cm spatial units, the stimulus is too big to be shown on the screen and I can only see part of it in the corner of the screen. I really need the stimulus to have precise size, and I don’t understand how to set it for a custom polygon.

The vertices I gave you were based on a size of 1cm, but I’m not an expert in using cm units (since they don’t work online).

If the position is 0,0 and the size is small enough to see, is it centred?

No, if the position is 0,0 and size is 1 cm it is not centered (see screenshot in my previous reply).

1 Like

What about at zero rotation? Please could you confirm you’re using the vertices I gave you?

Here is how the stimulus looks with 0 deg orientation

Here is the settings for polygon component

What are you using to make the central dot?

What happens if you try a square [[-3.5,3.5],[-3.5,-3.5],[3.5,-3.5],[3.5,3.5]]

To make central dot I used text component with dot (0,0) position, 0 orientation
It shows square in the center of the screen with given vertices

As of 2022.1.0, Polygon stimuli have an anchor parameter which lets you choose which corner of the stimulus is at its position. So if you set its anchor as any of the bottom options it should rotate around the bottom point rather than the center.

I was hoping that it would rotate about the origin of the points I’d specified.

Even after changing anchor parameter to bottom option, the stimuli are not rotated around the center. I used both position custom code pos1=( cos(x1)*0.5, sin(x1)*0.5) as well as 0,0 position, but still the position of stimuli is offseted from center.
Maybe my position code is not correct?