Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

help with pseudocode- displaying a square revolving


  • Please log in to reply

#1
Japstar

Japstar

    Member

  • Member
  • PipPip
  • 94 posts
Hi

I need some help with pseudocode (i'm doing it in school)

The question is that we have to display a graphic of a number of square revolving at a common point. I attatched an image of what the graphic should look like.

I got no idea where to begin, so if anyone knows Pseudocode, can you please help me.

Thanks in advance
Japstar

Attached Thumbnails

  • diagram.jpg

  • 0

Advertisements


#2
darth_ash

darth_ash

    Member 1K

  • Member
  • PipPipPipPip
  • 1,382 posts
Hi Japstar,
You did'nt mention the no. of squares that must be displayed so I will be assuming that its a user input.
The logic I thought was to consider only one side of the square, rotate it around the Co-ordiante axis, and draw the rest of the 3 lines of the square relative to it.
I'll be rotating the the side of the square around (0,0). And angle between two squares will depend on the no. of squares the user has asked to display.


Below is the list of variables I'll be using:
l: Is the length of the side of the square
i: The index variable to increment the angle.
angle: The angle calculated according to the no. of squares the user want to display.
x: The x co-ordinate of the other end of the first line.
y: The y co-ordinate of the other end of the first line.
n: The no. of squares the user want on the screen.

I'll illustrate two iterations of the logic with a diagram(pls. excuse the quality of the fig.; I suck at drawing), refer the fig. below:
sq_eg.JPG
Initially our line under consideration is drawn a 0degrees, the rest of square is built on basis of it. In this e.g. I will take angle as 60degrees. I tilt our main line by 60dgs; now all we have to do is find the co-ordinates (x,y) to draw our main line. This can obtained from the formulae below:
x=l*cos(60)
y=l*sin(60)
The rest of the square can be built on basis of it.

i=0
angle = 360/n
while(i<360)
{
	x = l*cos(angle)
	y = l*sin(angle)
	line(0,0,x,y);	//the lib. function to draw a line
 //this is only to draw the first line, I leave the rest of the lines to you
	line(__ , __ , __ , ___)
	line(__ , __ , __ , ___)
	line(__ , __ , __ , ___)

	i+=angle

}

Note if you intend to implement this code on a actual PC: The computer screen only has the 4th-quadrant of the co-ordinate system; so you will have to take an arbitary origin.

Edited by darth_ash, 05 March 2006 - 09:41 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP