Room dimentions ratio, propability function.

Started by
5 comments, last by The C modest god 18 years, 6 months ago
I want to create random sized rooms for my game. So, given a certain area of a rectangle room I need to decide what will be its dimentions (X and Y). To simplfy the problem, I only need to randomly roll the proportion between the room's X and Y. While R>1 is a constant of the largest ratio possible. The values of the random variable should be between 1/R to R. Lets call this random variable L. So for some number 1<a<R, P(L<1/a)=P(L>a). The final request from L, is that E(L)=1. Also, L must be generate from a combination of one or more unity (U(,)) random variable. Can you help me find this random variable?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Advertisement
There is something I have thought about.
To have random variables X~U(1, R), Y~=(1/R, 1) and a fair coin.
So in propability 0.5 L = X and in propability 0.5 L = Y.
However, EL is not 1.
Or maybe I had a mistake in my calculations of EL?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Trying to come up with a distribution D(1/R, R) that meets your requirements isn't the right way to go about this, or at least it's extremely difficult. Let's say you consider the ratio of X-to-Y, with a range [1,R] that satisfies the constraint XY = A (some area). When you adjust the X-to-Y ratio range to be [1,1/R], it's really the same as the ratio of Y-to-X, over the range [1,R]. So the issue here with a single distribution is that you're dealing with what I would see as a local "compression" over [1/R,1], since it's equivalent to [1,R] if you just switch X and Y however you have two different size ranges for something that's geometrically equivalant. This problem is formalized by the constraint you mention in your post: P(L<1/a)=P(L>a). I'm sure that such a distribution exists, however coming up with it probably involves some complex math and statistics.

But using the apparent symmetry around 1 of [1,R] for X-to-Y and [1,R] for Y-to-X, we can decompose the problem into two uniform distributions M~U(-1,1) and L~U(1,R). L will be the final ratio, however if M>=0 then the ratio is for X-to-Y and if M<0 then the ratio is for Y-to-X. Using your constraints, you can come up with a system of equations to solve for either X or Y as a function of the ratio and the area A, and then using this ratio you can solve for the other length. This construction satisfies all your requirements.

[Edited by - Zipster on October 7, 2005 8:10:22 AM]
The requirement that E(L)=1 seems very arbitrary to me. You probably need something else and didn't think it through. Did you put that requirement so you don't get too many or too few oblong rectangles? Any natural distribution with E(L)=1 will generate more values under 1 than over 1.

It looks to me that the natural quantity to consider in this problem is not the ratio of the too lengths, but the angle that a diagonal forms with one of the sides. That angle would be between atan(1/R) and atan(R), but it turns out that those two angles can be written as 45º-delta and 45º+delta. I think a uniform distribution U(45º-delta, 45º+delta) for the angle will do just fine, or any other symmetric distribution around 45º.
I think the simplest solution is something like this:

Generate a uniform random number L between -R and R
If L < 0, then X = -L, Y = 1.
If L > 0, then X = 1, Y = L.
If L == 0, then X == Y == 1.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Those equations don't take the area constraint into account. Whatever solution you use to find the ratio, you're still going to have to go back and solve for one side and then the other. The angle-based method looks clever, though. As long as you work off symmetry things should be fine.
I did something like what you have wrote.
With X~(1, R) and then using a coin to decide which axis to use.
You were right, the demand that EL=1 was pointless. Because EL is the factored average (dont know how to say it), not a normal average.
What I needed is actually that the nomral average will be 1.

Thanks for all the help.
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.

This topic is closed to new replies.

Advertisement