Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.objective-c > #201 > unrolled thread
| Started by | modelling.data@gmail.com |
|---|---|
| First post | 2015-11-13 08:35 -0800 |
| Last post | 2015-11-13 10:39 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.objective-c
Setting coordinates and sizes of a set of objects in a window modelling.data@gmail.com - 2015-11-13 08:35 -0800
Re: Setting coordinates and sizes of a set of objects in a window "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-13 18:31 +0100
Re: Setting coordinates and sizes of a set of objects in a window modelling.data@gmail.com - 2015-11-13 10:39 -0800
| From | modelling.data@gmail.com |
|---|---|
| Date | 2015-11-13 08:35 -0800 |
| Subject | Setting coordinates and sizes of a set of objects in a window |
| Message-ID | <fe5fda06-5c9a-4ddf-b91a-f5e28985aa3b@googlegroups.com> |
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.
1) I think I need to find a formula to compute coordinates of each
rectangle.
I am planning to use a for loop:
for ( i = 0; i < rows; i++)
for (j = 0; j < columns; j++)
such that every N_{ij} contains a rectangle.
To correctly place all rectangles I have to find the (x,y) of the first
rectangle, including the size of space between the rectangle and left and upper
planes of the window.
Because coordinates of any given object are set for the upper left corner
of the object, then next (second, etc) rectangle should have the following
coordinates:
(X of the first rectangle + width of the 1st rectangle + space between
1st and 2nd;
Y is the same for all rectangles of a given row).
The function that creates such objects takes the following arguments:
X coordinate, Y coordinate, width, height.
I could set an arbitrary width and height, but I do not understand how
to compute it based on the parameters of the window (width and height).
For example, if I set width 50 and height 20 of a rectangle, is it big,
or is it small? How is it related to sizes in cm or mm?
I understand what I need in words, but I don't see the correct mathematical
implementation.
Thank you!
[toc] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2015-11-13 18:31 +0100 |
| Message-ID | <87ziyh24cl.fsf@kuiper.lan.informatimago.com> |
| In reply to | #201 |
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
[toc] | [prev] | [next] | [standalone]
| From | modelling.data@gmail.com |
|---|---|
| Date | 2015-11-13 10:39 -0800 |
| Message-ID | <00376e44-f7ca-4e82-abe1-9c1ef0d05312@googlegroups.com> |
| In reply to | #202 |
<snip> Thank you very much for your help and this wonderful and helpful explanation. Indeed, I am learning everything from scratch (not basic math, of course; that's been drummed in thoroughly enough), although I am far beyond 16 yo )
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.objective-c
csiph-web