Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw multiple primitive lines which start at the center of the screen and end at the edges of the screen, traveling at specific angles:

enter image description here

How can I set the angle for each line?

Here is my code where I draw only one line from the middle of the screen to the top of the screen.

LineVertices = new VertexPositionColor[2];
LineVertices[0].Position = new Vector3(graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2, 0);
LineVertices[0].Color = Color.Red;
LineVertices[1].Position = new Vector3(graphics.GraphicsDevice.Viewport.Width / 2, 0, 0);
LineVertices[1].Color = Color.Red;
//Draw call 
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, Line2Vertices, 0, 1);
share|improve this question

This is essentially simple trigonometry. Assuming the center of the screen is your origin (i.e. (0, 0)), then it's pretty straightforward:

x = length * sin(angle);
y = length * cos(angle);

Just insert the proper numbers and you end up with your vertex coordinates.

share|improve this answer
Thank you very much. That helped a lot. I'm really bad at trigonometry. I need to get a trigonometry book. Thanks again ^_^ – user50637 Aug 16 '14 at 10:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.