Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / a little math help needed

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2003 02:25
I'm trying to simulate the effect of a ball rolling on a piece of cloth which is suspended in the air. So as the ball hits the cloth, the cloth would form around the ball slightly and stretch down slightly from the weight of the ball. I'm using a matrix for the cloth. I pretty much have the collision taken care of. But I'm not sure how to determine the correct amount to reduce the height of the matrix tiles. I'm guessing something to do with intersect object maybe?

Below is what I have so far, just to give you a better idea. DBP


Floyd
22
Years of Service
User Offline
Joined: 11th Sep 2003
Location:
Posted: 3rd Nov 2003 07:22
To form the impression of the ball in the cloth, I would determine the height of the lower hemisphere of the ball for each point over the appropriate vertex of the matrix and lower that matrix point if necessary. Probably the more computationally expensive problem is determining how to stretch the surrounding area of the cloth. To do that rigorously would probably require the finite element method or something like that (with which I will be no help). To fake it, I would probably use an averaging method.

At the start of each averaging iteration, I would mark the points of support for the cloth and the points of impression as unchangeable. The naive solution would be to just average each changeable point with its neighbors and repeat that enough times to allow changes to move across the matrix. But if the points of support were fixed, all the variation would stem from the impression of the ball. So on the first iteration, I would average all points bordering the impression and I would mark all those points on a map I would use for the next iteration which would average all those points and points bordering them. And so on until it looked acceptable.

I you're doing this in real time, I'm guessing you'll pretty quickly run into limits on the number of iterations that you can do, but then, I've never implemented anything like this.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2003 09:27
As I'm using a matrix, the update matrix command will surely slow things down as well. I guessed a method of averaging for the stretching as well, but I haven't gotton to that yet. I still need to figure out the proper point of collision between the ball and the matrix. Time to open that old geometry book.
Floyd
22
Years of Service
User Offline
Joined: 11th Sep 2003
Location:
Posted: 3rd Nov 2003 12:35
Well, I haven't worked all this out, but the formula for a general sphere is:

(x-xo)^2 + (y-yo)^2 + (z-zo)^2 = r^2,

where xo,yo,zo are the coordinates of the center. So you'd be looking for collisions on the matrix in a region bounded by xo+-r, zo+-r and points where (x-xo)^2 + (z-zo)^2 > r^2 would be outside the sphere.

There are probably a number of things you can do to speed things up. I'm not very experienced with DB, so I have little idea how fast things are, but if updating the matrix is slow, you should have a copy of the matrix vertex heights in an array and do all the reads and writes of various iterations using that array and finally update the matrix when you have a final result. So you're never reading values from the matrix and only writing each element once per iteration.

If solving for values of the sphere turns out to be too time-consuming, you could probably just precompute a 2-dimensional matrix for the lower hemisphere of your sphere and figure some way to pick a close point to the vertex you're interested in. The indices would be derived from x and z values and the array values would probably be offsets from the center height (probably negative values that would be added to the center height). I would guess this would be considerably faster that using the formula. Given that the array will represent a square area and the sphere will have a circular projection, you might just fill in elements of the array which lie outside that circle with very large values which will never collide with the matrix, so you don't have to calculate which points are inside that circle.

Hope some of this helps. I've thought about trying to implement solutions like this before, but haven't attempted it.

Login to post a reply

Server time is: 2026-07-26 16:03:06
Your offset time is: 2026-07-26 16:03:06