Beginners Task #3

Online C++ programming contests.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard, raimo

Beginners Task #3

Postby tougo » Wed Jun 23, 2004 8:17 pm

Beginners Task #3: Transformations

I thought that it is a very usefull excercise for those that like to go into some mathematical concepts of
game programming. Iam sure it needs a little bit of thought but overall is very simple. The results can very well be just ascii files or just output on the screen, it doesn't really matter.

There are two versions of the task a 2d and 3d one. The 3d might be more difficult so you can just try the 2d

1st version

Write a program that produces a n set of points [xy] that are part of a circle and then calculated the largest
square that can be fitted in the circle and transform the initial coordinates of the cirlce to that of the square's.

INPUT

(P) number of point:
radius:

OUTPUT

(P) coordinates:


2nd version

Write a program that produces a n set of points [xyz] that are part of a sphere and then calculated the largest
cube that can be fitted in the sphere and transform the initial coordinates of the sphere to that of the cube's.

INPUT
(P) number of point:
radius:


OUTPUT

(P) coordinates:


a visual representation would make things easier I think. I did my best :). I hope someone like it.
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Postby leas5040 » Wed Jun 23, 2004 9:59 pm

This looks kind of fun. Could you post a sample output? Is it supposed to show the square in the circle, with the coordinates of each crossing vertex?
"Given enough time, man can do anything with a bit of string and some Tinker toys." Bruce Bolden, Senior Instructor at the University of Idaho.
User avatar
leas5040
 
Posts: 1214
Joined: Mon Apr 12, 2004 9:51 pm
Location: Moscow, ID

Postby MXP » Wed Jun 23, 2004 10:47 pm

I dont understand what you mean.

Write a program that produces a n set of points [xy]

Do you mean "a set of points (x, y)"? If so how does that fit with the example input?

Code: Select all
(P) number of point:
radius:


transform the initial coordinates of the cirlce to that of the square's.

A square is made of 4 coordinates. To which would you like us to transform the circle?
Need information on a function I've posted? Chances are it's at the MSDN.
MXP
 
Posts: 6506
Joined: Mon Sep 22, 2003 5:27 pm

Postby tomcant » Thu Jun 24, 2004 1:27 am

If I understand correctly, this is quite simple... but I won't give anything away :wink:
If it wasn't for C, we would be using BASI, PASAL and OBOL.
User avatar
tomcant
 
Posts: 3101
Joined: Tue Sep 23, 2003 1:56 am
Location: Colchester, UK

Postby RecursiveS » Thu Jun 24, 2004 3:09 am

Stickied for a while, as usual. :)
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK

Postby tougo » Thu Jun 24, 2004 4:29 am

If I understand correctly, this is quite simple


Yes it is, that's why It's a Beginners task ;)

A square is made of 4 coordinates. To which would you like us to transform the circle?


each coordinate of the circle corresponds to a coordinate of the square ..if you have a cirlce made from let's say 40 points...then you'll have a square made from the same points...you actually move the circles points in to the corresponding position in the square.

the fitting is quite easy...(can't be easier) the transformation is easy as well but it can be tricky (for the 3d at least)
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Postby Alvaro » Thu Jun 24, 2004 4:45 am

Do you mean you have to project the points on the circle to points on the square? Like, joining a point in the circle with the center of the circle and then finding the intersection with the square? And what is the square, exactly?

Can you give us a sample input and the expected output?
User avatar
Alvaro
Moderator
 
Posts: 5185
Joined: Mon Sep 22, 2003 4:57 pm
Location: NY, USA

Postby tougo » Thu Jun 24, 2004 5:24 am

yes exactly that...Alvaro
I'll try to post a screenshot or else just a list of points of an example later this day
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Postby tougo » Thu Jun 24, 2004 6:38 am

i don't know if these screenshots will help ...but here it goes

ignore the programme that displays the points it was designed for another purpose. ignore the red cross as well it just shows the weight of the points

PS. The output can be a lot better (not missing any points in the edges that the screenshots). It was done in a hurry and i tried to maintain equal lengths between points (it was kind of a disaster :) )


Image
Image
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Postby t i l e x » Thu Jun 24, 2004 7:34 am

Now that is annoying.. I know how to do it but I never learned the maths required for this ( this year again... lol ) if it's what I think.
User avatar
t i l e x
 
Posts: 3604
Joined: Wed Dec 03, 2003 3:59 pm
Location: Québec (Canada)

Postby RaH » Thu Jun 24, 2004 9:54 am

Colin I think what is meant is the user enters the initial [x,y] coordinate, then the radius of a circle. Your program must then calculate off the [x,y] coordinate to create a square or cube to encompass the circle.

Correct me if I'm wrong on this one.
"Codito ergo sum"
RaH
 
Posts: 258
Joined: Mon May 24, 2004 11:59 am
Location: Va Beach, Va.

Postby thompsok » Thu Jun 24, 2004 10:25 am

I've got an idea, why don't we all figure out the math on how to calculate the coordinates of a circle if you are given a starting point and the radius of the circle. Then we all figure out how to calculate the largest square that can fit in that circle.

Then we all stop right there satisfied that we could produce the program if some consensus were ever achieved on what the function is going to take for arguments and what the output is going to be. Here is what I would like to see from the OP.

Code: Select all
// function template
void FigureStuffOut(int Radius, int NumberOfPoints)
{
     // figure out what goes here...
     for (int i =1; i <= NumberOfPoints; i++)
          cout << // a set of coordinates;
   
     cout << "the size of the largest square is" << SquareSize << " x " << SquareSize << endl;
}


a little pseudocode with some sample output that doesn't give away the answer. I love the sample output by the way
ignore the programme that displays the points it was designed for another purpose. ignore the red cross as well

So just ignore everything on the screen? I think making a program that produces blank output might be too easy even for a beginner project.

I'm sorry if this sounds pissy, but seriously if you're going to write a beginner task or a programming challenge then you have to write the instructions almost as clearly as if you were writing the program. If you leave things vague, then you end up with a lot of people asking questions...and if they are getting different answers then eventually someone who doesn't have any patience (me) is going to send a flame.

Sorry to flame, but I had to get that off my chest. And if I'm the only person who doesn't understand what the output should be and what should be send into the function, then I'm sorry for being stupid.
Headstrong Padawan programmer who has much to learn about the living force.
thompsok
 
Posts: 174
Joined: Wed Feb 04, 2004 10:46 am
Location: Minnesota, USA

Postby tougo » Thu Jun 24, 2004 10:25 am

enters the initial [x,y] coordinate


the initial coordinates can be just [0,0]

the radius and the number of points are enough to create a circle
I never learned the maths required for this


HINT: if you know the what radians are (iam sure you know) and the pythagorean theorem ...you are half a way in solving it
It can be solved with basic trigonometry...

EDIT (because i don't want to make a new post)

The results can very well be just ascii files or just output on the screen, it doesn't really matter.


I knew in doing something like these screenshot was not easy that why i said that the program could just output a set of coordinates.

having as an output just the 4 coordinates or the length of the edge of the square is too easy (if you sit down and think) even for a 12 year old kid

sorry if I didn't explain things properly. but I think I did
Last edited by tougo on Thu Jun 24, 2004 10:34 am, edited 1 time in total.
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Postby RecursiveS » Thu Jun 24, 2004 10:31 am

I've just noticed the last two were moved to contests.

Unless anyone objects I'll move this one as well :)
User avatar
RecursiveS
Site Admin
 
Posts: 1236
Joined: Thu Sep 18, 2003 8:33 am
Location: Dorset, UK

Postby tougo » Thu Jun 24, 2004 10:51 am


ignore the programme that displays the points it was designed for another purpose. ignore the red cross as well



Well this program was written by me and it display files with [xy] or [xyz] coordinates as points using directX. when i said ignore it i meant the menu..because as you noticed there are options like RenderMode (actually is just a triangulation) and tools etc.. I just wanted to show you how the circle and the square look like in points (someone asked for a shot)

sample of file of the circle (with rounded values) radius set to 10
Code: Select all
0 20 0
3 20 0
6 19 0
9 18 0
12 16 0
14 14 0
16 12 0
18 9 0
19 6 0
20 3 0
20 0 0
20 -3 0
tougo
 
Posts: 432
Joined: Sat Oct 04, 2003 9:18 am
Location: Athens / Greece

Next

Return to Contests

Who is online

Users browsing this forum: No registered users and 1 guest