0
$\begingroup$

I have a line that represents an axis, on the computer's screen, it has a model domain and a screen domain. For example the model domain can be [2, 10], and the screen domain [50, 400].

I need to move the first (or last) model domain number, to a specific screen location, without affecting anything except the first (or last) point of the line. For example, normally with the domains given above the 2 from the model domain would have a screen location of 50. Now I want that the 2 has, instead, for example, a screen location of 100. And to do this I have to change the location of the first point in the model domain. The screen domain must stay intact. The last point of the model domain also can't move.

My first approach was to map the screen domain offset (50 in this case) to a model domain offset and subtract this from the first (model) point of the line, which basically makes the model domain "expand" beyond the first point, effectively "moving" my point to the right (imagining an x-axis now). The problem with this, is that it doesn't consider that when expanding the model domain of the line, the ratio changes, so when I map from model domain value to screen domain value, it will not end at the screen position where I intended to move it.

So I have to integrate this ratio change into my equation. The problem can be described in short as "find a new start model domain value for line, such that the point with domain value X gets a new screen location Y".

Just to show that I "tried something", though it's ridiculous, I made some attempts, using the equation to calculate the ratio as starting point, e.g.

model domain value = screen domain value * model domain length / screen domain length

For the example above:

2 = 100 * (8 + X) / 350 where X is the domain length "expansion" I need for the equation to become true, that is, such that the domain value 2 has a 100 screen location, but the result didn't make any sense. I feel I'm missing something very basic but now my head is closed. Appreciate any help!

$\endgroup$
1
$\begingroup$

$$ T:A\to B $$ $$ \{\lambda \in [a,b]\to[c,d]\} $$ $$ T: m\lambda+n \Rightarrow $$ $$ m\cdot a + n = c \\ m\cdot b + n = d $$ $$ m=\frac{c-d}{a-b} \quad n = \frac{cb-da}{b-a} $$


So if you want to go from one Domain $[a,b]$ to another $[c,d]$ you just need:

$$ T(\lambda)= \left(\frac{c-d}{a-b}\right)\cdot \lambda + \frac{cb-da}{b-a} \quad \lambda \in [a,b] $$


If you want to return just apply the inverse function of $T(\lambda)$

$\endgroup$
  • $\begingroup$ Thanks for answering! I don't fully understand, what would be $\lambda$ in my example?. What role do play the screen coordinates in this equation? $\endgroup$ – Ixx Jul 28 '16 at 9:59
  • $\begingroup$ $\lambda \in [a,b]$ i.e $\lambda$ is any point in the model domain in this case $[2,10]$ and $T(\lambda)$ allow you to go from the model domain to the screen domain ($[c,d]$ in this case $[50,400]$.) In general if you want to go from domain to another just change the $[a,b]$ and the $[c,d]$ $\endgroup$ – Anonymous Jul 28 '16 at 18:46
  • $\begingroup$ Hmm, ok this is a simple ratio calculation - I've doing this so far to translate between the domains. I thought my question was something different but realising now it comes down to the same... as I said, it was late and my head was blocked the other day :D let me double check... $\endgroup$ – Ixx Jul 28 '16 at 18:55
  • $\begingroup$ Indeed, my first point would have a value of 1.3333... lol. $\endgroup$ – Ixx Jul 28 '16 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.