Archived

This topic is now archived and is closed to further replies.

a question about math

This topic is 5336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello, How would I normalize a 1d (that''s right, one diemsional) vector so that as distance aproaches 0, scale aproaches 2? In other words, I need to take a distance between two points (1 d) and based on that distance create a scaling factor for the size of an object given the above relation. I haven''t taken algebra in quite some time, as you can tell.... Peace, Thomas

Share this post


Link to post
Share on other sites
Well, if your vector is truly 1D, then the scaling factor is simply the reciprocal of the magnitude.

EDIT: tho I have to admit, I'm not sure what you mean by "as length approaches 0, scale approaches 2". Why 2?


How appropriate. You fight like a cow.

[edited by - sneftel on May 5, 2003 4:37:25 PM]

Share this post


Link to post
Share on other sites
A point is at least 2D, having two dimensions: X and Y. It can also be 3D, having X,Y and Z.
So something is wrong with you question I guess...

¬NeWX

Share this post


Link to post
Share on other sites
what do you mean by reciprocal of the magnitude? And I never said that I want to normalize a point. Just a vector. A vector is just another way of representing a number (or set there of).

Here's the thing:
I'm trying to re-create the "morphing" effect on the mac osx dock. What I want, is that as the distace from the mouse to the icon aproaches zero, I want it to be scalled by a value that aproaches 2. So, I need to normalize my distance, so that I can figure an apropriot scaling factor.

Peace,
Thomas


[edited by - CrackMonkeyT on May 5, 2003 4:47:59 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by NeWX
A point is at least 2D, having two dimensions: X and Y. It can also be 3D, having X,Y and Z.
Uh? Why not 1D, having just X? Or go wild, 4D, having X,Y,Z and e.g. T.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
scale = 2^(1/(K*distance+1))

Play with K.
smaller K(K<1) is gonna give u a smoother transition.
I think.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
scale = 2^(1/(K*distance+1))

Play with K.
smaller K(K<1) is gonna give u a smoother transition.
I think.

Share this post


Link to post
Share on other sites
take the distance from an icon to a point (x,y).
Then the size of the icons are 2-op(dist), where op can be any operation,i.e., sqrt(...). The distance between two icons are 1.

[edited by - kspbergstrom on May 7, 2003 5:06:41 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by CrackMonkeyT
what do you mean by reciprocal of the magnitude? And I never said that I want to normalize a point. Just a vector. A vector is just another way of representing a number (or set there of).



Not really. A vector is a magnitude and direction. Representing a vector as a ''set of numbers'' isn''t strictly necessary to the concept of a ''vector.''

quote:

Here''s the thing:
I''m trying to re-create the "morphing" effect on the mac osx dock. What I want, is that as the distace from the mouse to the icon aproaches zero, I want it to be scalled by a value that aproaches 2.



So you want a function f(x) such that the limit as x approaches zero is 2? Do you want it to approach from the minus side or the positive side?

Note that you can come up with many other functions that have the same property. The AP has a nice once. I''m still not sure exactly what you''re asking for, so I can''t be more specific, sorry.

quote:

So, I need to normalize my distance, so that I can figure an apropriot scaling factor.



Normalizing a vector means you maintain the direction while converting to a unit magnitude. This doesn''t sound like what you''re trying to do.

Share this post


Link to post
Share on other sites
quote:

Not really. A vector is a magnitude and direction. Representing a vector as a ''set of numbers'' isn''t strictly necessary to the concept of a ''vector.''


Actually a "vector" is an "n-tuple" or a set of n values, which don''t even have to be real numbers! The concept of "a magnitude and a direction" (polar co-ordinates) is only applicable in R^2, that is vectors that are pairs of real numbers. Even if you go to R^3 (1 extra co-ordinate per vector), you require more information than a single magnitude and direction.

Again, your definition of "normalizing" is only applicable to real inner product spaces as the definition of "direction" only makes sense here... not a big issue really as in game programming you rarely consider otherwise, but I just figured I''d generalize the definition for any interested parties And I agree, "normalizing" isn''t really what you mean here...

To respond more directly to the question though, you''ll need to decide more information about exactly how you want your effect to be before we can decide on the specific equation. You''ve basically given us that "lim(x->0+) [f(x)] = 2" or maybe as far as f(0) = 2.

Now you need to decide things like:
- Where do you want the scaling to begin? What is the minimum scaling factor? 1? At what distance does that occur? Beyond that distance is it just set to 1?
- What "shape" do you want the scaling curve in the valid range (the above maximum distance value, to however close you want to go to 0... if you''re talking pixels, probably 1)? Linear? Quadratic (parabolic)? Reciprocal (hyperbolic)? Higher-order polynomial (arbitrary shape, even based on control points if you like)?

My point is that before that question can be answered, you really need to decide more explicitly what you want. Then we can go about designing "the perfect function" so that you can effectively have f(d) = what you want.

Share this post


Link to post
Share on other sites
okay, this is becoming quite a bit more complicated than I had hoped. I''m not complaining, mind you, I''ve already learned quite a lot. Here is what I want:

The user moves their mouse along the x axis. I''m only concerned with distance along the x axis. All others can be ignored. As the distance from the mouse to the icon becomes shorter, the icon grows to be bigger. The minimum size that an icon can be is the size that it started out as; at the moment 50x50. The maximum size that it can be is twice its origional (100x100). The scaling "curve" if you were to graph the function I want to be roughly logorithmic, or even asuptotic (spellng?) in that it is a steady, fluid curve that never doubles back on itself. The only value going into the function for f(x) is the distance from the mouse to the icon (abs(mouse_x - icon_x)) direction I don''t care about because as I get close from one side it gets bigger, and as I get farther away continuing in the other direction it gets smaller again.

I hope that makes it roughly clear. If you are still confused find someone with a mac or go to comp usa or your local mac store and check out the dock at the bottom of the screen. Some of you may be familiar with a similar effect from nextStep, which is the basis for mac os x.

Peace,
Thokmas

Share this post


Link to post
Share on other sites
interpolation

scale = (maxscale-minscale)*Factor + minscale;

factor will be from 0 to 1, 0 is farthest away form the object, and 1 is on it so do like


scale = (maxscale-minscale)*(actualdistance/maxpossibledistance)+minscale;


maxpossible distance will be depenedent on the resolution iguess the far edge away from the task bar, also if u want there to be a threshold about halfway through the screen u could do


scale = (maxscale-minscale)*(max(0,actualdistance/(maxpossibledistance-thresholddistance)))+ minscale;


you may have to tweek those equations but i htink they are almost right.


hope that helped, or im an idiot...

Share this post


Link to post
Share on other sites
Why don't you use something like "e^(-x^2) + 1" then. It's a very fluid curve, will look great, and you don't even need to worry about taking the absolute value (the graph is semetrical about the y-axis already). It is also logarithmic in nature as you requested.

My suggestion therefore would be that you use the following formula. If d is your distance:

ScaleFactor = e^(-d^2) + 1

Which will produce a value between 1 and 2, for ANY input x. I'd also recommend that you do a simple check that if abs(d) > some reasonable value, just set the Scale Factor to 1, to avoid the far away icons from jittering.

Secondly if you need to tweak the effect ranges, just substitute (d/c) for d in the above equation. The value of c will control how far away the scalaing starts, etc (although inversly... ie. larger values of c will make it start CLOSER).

Anyways that's the basics. There are plenty of things you can do with that one function, and if you don't like it, there are plenty more options. Good luck with it, and feel free to come back and ask for more help if you need it!

PS: it's spelled "asymptotic"

[Edit] The above linear interpolation method is fine, but it won't give you the "smooth" curve that you are looking for. Graphically, it will be a line which at zero hits a sharp corner. The logarithmic function will be much "smoother". Just graph them both and see what I mean.

[edited by - AndyTX on May 6, 2003 9:57:54 AM]

Share this post


Link to post
Share on other sites
uhm, that looks like what you want...

f(x) = 1/((x*n)^m+0.5)

you can chose whatever number you like for n and m

[edited by - novum on May 6, 2003 10:11:12 AM]

Share this post


Link to post
Share on other sites
okay, I can see the flames already because of obvious issues of screen res, etc. but I just divided the distance by 200 (all screen coords in the api I''m using are floats, so decimals are okay) and my function is (2 - sqrt(distance)). It makes it nice and smooth, and I just have a check that if at any time the size of the icon drops below its base size, then set it to its base size. The extra check slows things down a bit, but only by about 4 operations per cycle, which no human being will ever notice. And if they do, they can kiss it.

Again, everyone, thanx for all your help! I hope that this thread is also useful to other people. I will try some of the functions that you all have given me and see if I like any of them better than what I already have. Thank you so much!

Over and out,
Me.

Share this post


Link to post
Share on other sites
Not a problem, and don''t worry about the "extra check"... it''s gonna be necessary no matter what. Plus, even with 100 icons, 100 if conditions is still negligable compared ot even drawing a single icon anyways

Share this post


Link to post
Share on other sites
It will never go over y=2 for x>=0 for odd m and will never go over y=2 for even m :D


[edited by - novum on May 8, 2003 10:48:08 AM]

Share this post


Link to post
Share on other sites
No no no... an UPPER BOUND check on the DOMAIN, not the range. The point is that after the cursor gets 2 or 3 icons away, you want to cap the icon size at 1x... not just NEAR 1x or anything... the if condition is necessary because what we want is a function like:

f(d) = { g(d) if |d|<100, 1 if |d| >= 100 }

Where d is the distance and 100 is an arbitrary pixel range maximum to begin scaling at.

[edited by - AndyTX on May 8, 2003 10:02:39 PM]

Share this post


Link to post
Share on other sites