[self solved] Math problem "logarithmic zoom factor&

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

[self solved] Math problem "logarithmic zoom factor&

Post by josh »

Self solved: scroll down for answer
I have a slider tool that will "zoom into the map", the slider tool gives me values from 0 to 100, and I have to translate this to a zoom level.

What I did was I took the farthest zoomed out (smallest scale factor) and the farthest zoomed in (largest scale factor)

The farthest zoomed in is Y
The farthest zoomed out is X

Let's say X = 0 and Y = 10, let's also assume A is the current zoom factor

A/Y = the % on the slider

but if X is anything other then 0 I need

(A-X) / (Y-X)

when I plug in the current zoom level for A it returns the % the slider should jump to for this current zoom level.

And to go the other way around:

(N(Y-X))+X

Where N is the % on the slider, this returns the zoom level we should move to (calculated after the user adjusts the slider)




OK all good, except now comes the hard part (for me at least)

The slider is too sensitive for zooming in, that is going from a view of the entire earth down to the state level takes up 65% of the slider, where it should take only 20%, so I took the log base 10 of every value before it goes into this equation:

(a-x) / (y-x)

This works great, the slider moves to the right position based on the current zoom level...


Now I have to undo this process. I have to take the percent and convert it back to zoom level, taking into account the log I used to get the % in the first place..

I tried sticking pow(10, X) for every variable (i really have no idea what i'm doing at this point)


Here is the code I'm using to get the percents based on the logarithm:


this works with the logarithms

Code: Select all

percent = ((Math.log(view_width) / Math.log(10)) - (Math.log(minzoom) / Math.log(10)) ) / ((Math.log(maxzoom)/Math.log(10))  - (Math.log(minzoom)/ Math.log(10) ));
this code is going from the % back to zoomlevel:

this works on a linear scale only, i need this to undo the code above

Code: Select all

zoomlevel = (	percent 	*	(minzoom - maxzoom) +maxzoom);

Who remembers their Algebra 2? Not me...



Edit:::

Code: Select all

zoomlevel=
	Math.pow(10,
	 	percent
		*
		(
		 	(Math.log(minzoom) / Math.log(10))
			-
			(Math.log(maxzoom) / Math.log(10))
		)
		+
		(Math.log(maxzoom) / Math.log(10))
	);
Figures I solve it no problem after a good night's rest... gawd I hate math
Post Reply