Posted by Anonymous User

Announcements | Last Post | |
---|---|---|

: Programming Students at UNISA School of Computing | 06/19/2019 02:01PM | |

SoC Curricula | 09/30/2017 01:08PM | |

Demarcation or scoping of examinations and assessment | 02/13/2017 07:59AM | |

School of Computing Short Learning Programmes | 11/24/2014 08:37AM | |

Unisa contact information | 07/28/2011 01:28PM |

Anonymous User
pyramid of death May 17, 2006 09:45AM |
IP/Host: ---.saix.net Rating: 0 |

Re: pyramid of death May 17, 2006 02:15PM |
IP/Host: ---.johncom.co.za Registered: 14 years ago Posts: 111 Rating: 0 |

Hee hee hee. This is really ghastly, I know. I've been avoiding writing this code for a while because it's distressing

What I intend to do is:

1. Bound the bottom of the pyramid (this is easy because it's a plane parallel to the xz plane).

2. Bound the top of the pyramid (again, easy, the height is all at point {0,1,0})

3. Bound on a plane parallel to the hypotenuse of each face. My thinking here is based on 2D thinking. If you were inside a right-angled triangle, you'd have to test every point to see if was on the inside of the hypotenuse. The mathematics don't appear to be that hard. Now you just have to "pretend" you're in 2D, calculate the hypotenuse, and then check whether you've crossed it or not. I hope it works.

What I intend to do is:

1. Bound the bottom of the pyramid (this is easy because it's a plane parallel to the xz plane).

2. Bound the top of the pyramid (again, easy, the height is all at point {0,1,0})

3. Bound on a plane parallel to the hypotenuse of each face. My thinking here is based on 2D thinking. If you were inside a right-angled triangle, you'd have to test every point to see if was on the inside of the hypotenuse. The mathematics don't appear to be that hard. Now you just have to "pretend" you're in 2D, calculate the hypotenuse, and then check whether you've crossed it or not. I hope it works.

Re: pyramid of death May 18, 2006 10:50AM |
IP/Host: ---.johncom.co.za Registered: 14 years ago Posts: 111 Rating: 0 |

I found something else that might be useful. Apparently, the dot product of two vectors defines the cosine of the angle between those two vectors. If you're working in 2D and you want to determine if a point is inside a convex polygon, then you define a vector for each edge of the polygon, and a vector from your point to the first vertex of the edge. The dot product of these two vectors is the cosine of the angle between them, and if all the dot products so calculated are positive, then the point is inside the polygon.

This might help. I haven't figured out exactly how, though.

This might help. I haven't figured out exactly how, though.

Re: pyramid of death May 22, 2006 03:12PM |
IP/Host: ---.bbtec.net Registered: 14 years ago Posts: 52 Rating: 0 |

hehehe....

its actually really simple - it clicked for me last year after a doodle or two - here's a hint:

thinking in 2d is the right place to start.

a pyramid has 45degree sides.

one 45 degree triangle has sides eg 1,1,hypoteneuse

another has 0.5,0.5,another hypoteneuse

any more and I may as well just give the answer. Geometry aside, the maths for the actual collision detection is nothing beyond what you learnt in primary school - forget dot products and trig.

its actually really simple - it clicked for me last year after a doodle or two - here's a hint:

thinking in 2d is the right place to start.

a pyramid has 45degree sides.

one 45 degree triangle has sides eg 1,1,hypoteneuse

another has 0.5,0.5,another hypoteneuse

any more and I may as well just give the answer. Geometry aside, the maths for the actual collision detection is nothing beyond what you learnt in primary school - forget dot products and trig.

Re: pyramid of death May 22, 2006 03:25PM |
IP/Host: ---.bbtec.net Registered: 14 years ago Posts: 52 Rating: 0 |

oops

went back and checked up on my code and actually did it a bit differently - the hint above will still get you thinking in the right way though... the thing about 45 degrees might be wrong, but the principle of thinking in terms of similar triangles of different sizes is on the right track.

went back and checked up on my code and actually did it a bit differently - the hint above will still get you thinking in the right way though... the thing about 45 degrees might be wrong, but the principle of thinking in terms of similar triangles of different sizes is on the right track.

Anonymous User
Re: pyramid of death May 29, 2006 10:52AM |
IP/Host: ---.saix.net Rating: 0 |

Re: pyramid of death May 29, 2006 11:25AM |
IP/Host: ---.johncom.co.za Registered: 14 years ago Posts: 111 Rating: 0 |

Ah. I did something different. Mr Halland sent me a mail in which he guided me towards the equation of the plane. He said to try to express it in terms of the y value, but I did it differently. Equation of the plane is Ax+By+Cz+D. If you plug your point's {x,y,z} into this and it is <= 0, you're outside the pyramid. Works fine.

Anonymous User
Re: pyramid of death May 29, 2006 10:49PM |
IP/Host: ---.saix.net Rating: 0 |

Re: pyramid of death May 30, 2006 09:06AM |
IP/Host: ---.johncom.co.za Registered: 14 years ago Posts: 111 Rating: 0 |

Re: pyramid of death May 31, 2006 08:30AM |
IP/Host: 209.212.120.--- Registered: 13 years ago Posts: 18 Rating: 0 |

Anonymous User
Re: pyramid of death May 31, 2006 10:23AM |
IP/Host: ---.saix.net Rating: 0 |

Re: pyramid of death June 01, 2006 10:45AM |
IP/Host: ---.bbtec.net Registered: 14 years ago Posts: 52 Rating: 0 |

hmmm... this thread seems to have changed topic, but my very poor hint earlier was just trying to point out that similar triangles have the same ratio between the two sides that make up the right angle... so once you have the vertical position of the particle you can very quite simply determine the maximum horizontal co-ord at that point...

to get the ratio we divide maximum height by half a side length (half because we want a right angled triangle around y-axis) ie 2/1=2

(because the pyramid stays the same you might as well assign the ratio as a constant)

now shift our y-value so that we measure "height" in the pyramid from the top (point at the apex=0 and at base = 2) ie 1-yval.

now to get the maximum horizontal simply divide our "height" by the ratio ie ratio/height=max.

if the horizontal values are more than max (or less than -max) just move them back inside with a while loop decremeting by a small amount.

so say we have a point (x,0,z)

height is 1-0=1

max value is 1/2=0.5

while(x>max)x-=0.001;

while(x<-max)x+=0.001;

etc.

whole thing is 5 lines of simple code... and don't forget to massage the y value into the -1...1 range first.

to get the ratio we divide maximum height by half a side length (half because we want a right angled triangle around y-axis) ie 2/1=2

(because the pyramid stays the same you might as well assign the ratio as a constant)

now shift our y-value so that we measure "height" in the pyramid from the top (point at the apex=0 and at base = 2) ie 1-yval.

now to get the maximum horizontal simply divide our "height" by the ratio ie ratio/height=max.

if the horizontal values are more than max (or less than -max) just move them back inside with a while loop decremeting by a small amount.

so say we have a point (x,0,z)

height is 1-0=1

max value is 1/2=0.5

while(x>max)x-=0.001;

while(x<-max)x+=0.001;

etc.

whole thing is 5 lines of simple code... and don't forget to massage the y value into the -1...1 range first.

Re: pyramid of death June 01, 2006 12:40PM |
IP/Host: ---.gprs.vodacom.co.za Registered: 13 years ago Posts: 4 Rating: 0 |

Hi Guys. The idea given br "Tripod" above is correct.

When we halve the height, we get half the pyramid and also the x and z range is also halved. Just decrease the x and z range by the decrease in height(y) and we get our boundaries.

Just draw a diagram on paper and play around. Thats how I fugured all these out.

Since the due date for the assigment has passed, here are some code

to help you guys out:

(I just hope this is not agaist any rules. If it is, I am sorry.)

bool TestPtInCube( point3 pt, GLfloat ln )

{

if ((pt[0] > 1) | (pt[0] < -1) | (pt[1] > 1) | (pt[1] < -1)

| (pt[2] > 1) | (pt[2] < -1)

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInCylinder( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

Ax = pt[0];

Ay = pt[1];

if ((sqrt((Ax * Ax) + (Ay * Ay)) > 1.0) // sqrt of the sum of sqrs of sides

| (pt[2] > 1.0) | (pt[2] < -1.0) // the end sides

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInPyramid( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

float Az;

float yLen;

Ax = pt[0];

Ay = pt[1];

Az = pt[2];

// The base length is always the length of pt(y)

// Only in the case where height = len of side = same len sides = (for square bases)

// When we move halfway from top pt, the base at pt will also be halved.

yLen = 2 - (Ay + 1); // Calc Len of y pt away from pt(0,1,0)

yLen = yLen /2; // since zero is mid-pt - half on either side of center.

// ie. when Len y = 1, the base is x = -0.5 to 0.5 = Len 1 = Len y. Same for z.

if ((Ax < -yLen) | (Ax > yLen) |

(Az < -yLen) | (Az > yLen) |

(Ay < -1) | (Ay > 1))

return false;

else

return true;

}

bool TestPtInContainer( point3 pt, GLfloat ln )

{

if (ContainerID == 1) return TestPtInCube(pt, ln);

if (ContainerID == 2) return TestPtInCylinder(pt, ln);

if (ContainerID == 3) return TestPtInPyramid(pt, ln);

}

When we halve the height, we get half the pyramid and also the x and z range is also halved. Just decrease the x and z range by the decrease in height(y) and we get our boundaries.

Just draw a diagram on paper and play around. Thats how I fugured all these out.

Since the due date for the assigment has passed, here are some code

to help you guys out:

(I just hope this is not agaist any rules. If it is, I am sorry.)

bool TestPtInCube( point3 pt, GLfloat ln )

{

if ((pt[0] > 1) | (pt[0] < -1) | (pt[1] > 1) | (pt[1] < -1)

| (pt[2] > 1) | (pt[2] < -1)

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInCylinder( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

Ax = pt[0];

Ay = pt[1];

if ((sqrt((Ax * Ax) + (Ay * Ay)) > 1.0) // sqrt of the sum of sqrs of sides

| (pt[2] > 1.0) | (pt[2] < -1.0) // the end sides

| ln > partLngth[partnumber]) // also check Length

return false;

else

return true;

}

bool TestPtInPyramid( point3 pt, GLfloat ln )

{

float Ax;

float Ay;

float Az;

float yLen;

Ax = pt[0];

Ay = pt[1];

Az = pt[2];

// The base length is always the length of pt(y)

// Only in the case where height = len of side = same len sides = (for square bases)

// When we move halfway from top pt, the base at pt will also be halved.

yLen = 2 - (Ay + 1); // Calc Len of y pt away from pt(0,1,0)

yLen = yLen /2; // since zero is mid-pt - half on either side of center.

// ie. when Len y = 1, the base is x = -0.5 to 0.5 = Len 1 = Len y. Same for z.

if ((Ax < -yLen) | (Ax > yLen) |

(Az < -yLen) | (Az > yLen) |

(Ay < -1) | (Ay > 1))

return false;

else

return true;

}

bool TestPtInContainer( point3 pt, GLfloat ln )

{

if (ContainerID == 1) return TestPtInCube(pt, ln);

if (ContainerID == 2) return TestPtInCylinder(pt, ln);

if (ContainerID == 3) return TestPtInPyramid(pt, ln);

}

Re: pyramid of death June 01, 2006 12:56PM |
IP/Host: ---.gprs.vodacom.co.za Registered: 13 years ago Posts: 4 Rating: 0 |

Re: pyramid of death June 01, 2006 01:33PM |
IP/Host: ---.bbtec.net Registered: 14 years ago Posts: 52 Rating: 0 |

Determinants are beyond the scope of the course (unless they changed it since last year)... probably good to figure out in the long run, but you don't need them yet.

the matrices are just facts so yes, "by heart", if you think its worth the effort as you will barely ever use them - at least for the course. OGL just uses them internally to do the transforms for you. Seem to remember figuring out some scheme to memorise them for them for the exam, but for most purposes you can just look them up for now. If you ever get into writing your own 3d engine they are good to know though.

AND FAR BETTER NOT TO CROSS THREADS ON FORUMS -

start a new thread and people who aren't intersted in pyramids might answer you, and info posted in them is easier to find later on.

the matrices are just facts so yes, "by heart", if you think its worth the effort as you will barely ever use them - at least for the course. OGL just uses them internally to do the transforms for you. Seem to remember figuring out some scheme to memorise them for them for the exam, but for most purposes you can just look them up for now. If you ever get into writing your own 3d engine they are good to know though.

AND FAR BETTER NOT TO CROSS THREADS ON FORUMS -

start a new thread and people who aren't intersted in pyramids might answer you, and info posted in them is easier to find later on.

Sorry, only registered users may post in this forum.