modelling.data@gmail.com writes:
Hello!
I would be grateful for help on the following issue, though I am
not sure that it's fully on programming - I think that it's more
math related.
I have created a window. A number of rectangles should be placed
in the upper half of this window being distributed within 5 rows and 10 columns, separated by some space.
The width of the window is 400, the height is 600 pixels.
How is it related to sizes in cm or mm?
Yes, how does it?
I understand what I need in words, but I don't see the correct mathematical implementation.
I'm not so sure.
You should first draw a model of what you want, and indicate the
parameters.
I will assume from your formulation that you have the origin of the
coordinate systems on the top left and the y axis downward, but notice
that on MacOSX, it's a normal coordinate system that is used, with the
origin on the bottom left of the window, and the y axis upward.
0,0 +---------------------------------------------------------------------------+
| |T |
| | | |L +-----------+ hs +-----------+ +-----------+ +-----------+ R | |--| w*h |----| | | | | |---------|
| +-----------+ +-----------+ +-----------+ +-----------+ |
| | vs xi,yj |
| +-----------+ +-----------+ +-----------+ +-----------+ |
| | | | | | | | | |
| +-----------+ +-----------+ +-----------+ +-----------+ |
| |
| +-----------+ +-----------+ +-----------+ +-----------+ |
| | | | | | | | | |
| +-----------+ +-----------+ +-----------+ +-----------+ |
| | |
| | |
| | |
| | |
| |B |
| | |
| | |
| | |
| | |
| | W*H| +---------------------------------------------------------------------------+
Here, T L B R are the top, left, bottom and right margins, in the window
of size W*H.
n*m is the number of cells you want to draw (in the example, n=4 m=3).
w*h is the size of the cells.
hs and vs are the horizontal and vertical separation.
Next, you can write some equations. It's a simple matter of making
additions:
Horizontally: L+n*w+(n-1)*hs+R = W
Vertically: T+m*h+(m-1)*ws+B = H
Already, you can notice that both equations are the same, so you need
only to solve one, and the other will be solved by variable
substitutions.
Let's take: L+n*w+(n-1)*hs+R = W
What are the unknowns?
You said W = 400 px.
N = 10
but you seem to be hesitant on the width w.
You completely ignored the horizontal separation hs, and the left and
right margins. Only about the bottom margin, you said you wanted it on
the upper half, so we know that B>H/2. But shall the bottom of the
cells be aligned with H/2, or shall them be somewhat higher? (perhaps
B=H/2+T ?).
It is up to you to decide whether you want a fixed size, a fixed
separation, or a certain relationship between them.
For example, you could choose to have w=hs*5.
In any case, in the equation:
L+n*w+(n-1)*hs+R = W
You have 6 variables, so to resolve it uniquely, you need to fix 5 of
them, to keep a single unknown. Or you need to add another equation
between those variables, if you have one more unknown, etc.
Assuming 2 equations:
L+n*w+(n-1)*hs+R = W
w=hs*5
and 2 unknowns: w and hs,
with 4 variables known:
L=20
R=20
W=400
n=10
You can easily solve it:
L+n*w+(n-1)*hs+R = W
w=hs*5
w=(W-L-(n-1)*hs-R)/n
w=hs*5
w=(W-L-(n-1)*hs-R)/n
5n*hs=(W-L-(n-1)*hs-R)
w=(W-L-(n-1)*hs-R)/n
(6n-1)*hs=(W-L-R)
w=(W-L-(n-1)*hs-R)/n
hs=(W-L-R)/(6n-1)
hs=6
w=30
Now we will assume that you know all your parameters.
Similarly, given one set of parameter, you can compute the cooresponding ordinate, and using the other set, the other coordinate using the same algorithm. For the coordinate xi, you can see directly from the drawing
that x0=L, and you can find x(i+1) in function of xi. This gives you a
recurent system:
x0=L
x(i+1)=xi+w+hs
It's a simple linear progression, so you can easily find a direct
formula for the ith coordinate:
xi=L+(w+hs)*i
So, mathematically, what we have is:
- equation systems (of the 1rst order, unless you start adding more
complex relations between your Pascal),
- recurent systems.
and not much more, all which should have been learned before 16 yo.
--
__parameters Bourguignon__
http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)