Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Smarter, more experienced friends...

Author
Message
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 3rd Aug 2004 13:45
I have a small problem that's been driving me a little nuts, can anyone here guide me?

What I want to do is to create a logarithmic scale slider bar, similar to that you might find on a slide rule. This means that finer increments take place on one end of the scale while progressively larger ones appear near the opposite end. But I can't seem to suss it out. I have copied the logarithm routines listed in the messages, but these are not helping me to create the scale display bar, can anyone help?

I need to be able to both display and calculate the values from the scale, just like you'd find in a slide rule application. I probably just need the proper formulae, but it's been making me nuts translating it into a build loop for DBC...


Thanks for any assist you may offer,
S.

Any truly great code should be indisguishable from magic.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 3rd Aug 2004 15:16 Edited at: 3rd Aug 2004 16:07
You may want something similar to this.
Create a scale range for the slide bar say 1 to 100
Create a value range for the returns say 1 to 50
Use this formula to get the values from the scale
value = Highestvalue/scale
and this formula to get the scale from the values
scale = Highestvalue/value

will give you a scale like this

This is a simple method and may not be what you want as I have never used a slide rule.

SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 3rd Aug 2004 16:40
That however is a linear scale, not a log based one. The scale I want is like;

value distance traveled
1.0 start of scale
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
2.0 one-third scale
2.25
2.5
2.75
3.0
3.5
4.0
5.0 one-half scale
6.0
7.0 two-thirds scale
8.0
8.5 three-fourths scale
9.0
10.0

and similar. Though I fully intend to scale it to the values used by the program, this is what you'd see on a slide rule.

S.

Any truly great code should be indisguishable from magic.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 3rd Aug 2004 23:42
Oh I see now I think you might be able to use an electronics formula for something like that. Do you want that exact scale or just something that acts like that? I don't think I can mathmatically match that scale exactly because at the start it takes 1 unit to be 1/3 scale then 5 units to be 2/3 scale then 3 units to be 3/3. Though circle formulas could possibly give you that if you get on the curve right.

SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 4th Aug 2004 04:57
Yeah, that's exactly the thing that's driving me nuts too. I know its based upon logarithms to create that such a thing, it's how a slide rule works. But getting my head wrapped around the problem in such a way as to code it is driving me crazy. I wanted to use it for a quantity control bar, like say a speed handle. Trouble is, the faster you go the more "coarse" the changes in speed become, because you're already moving too fast to make small adjusts. And the reverse is true on the other end, you can make very small adjusts when moving slowly, but have to make larger changes to accelerate. (Relativistic theory as it were.)

Anyway, maybe someone, somewhere, knows the process needed....
S.

Any truly great code should be indisguishable from magic.
Lost in Thought
20
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 4th Aug 2004 06:31
Oh well. If I find anything I'll let you know. Or if I can find a slide rule somewhere maybe I can see it work and know more about how it works. I just found this though http://www.geocities.com/Athens/Delphi/5136/slide.html
I'll check it out tonight when I get home and see what I can come up with. It looks like a slide rule is actually 2 slide bars to me and the starting position and length (or reference position) of one slide bar is compared to the second (fixed length) slide bar at different positions. There are also a few formulas there that may be of some help.

Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 4th Aug 2004 14:58
What exactly are you looking for in your program? An equation so you can input one number and get a result? I am familiar with logarithmic equations, having taken math through Calculus. Do you want the equation for a logarithmic graph?

y=a^x

A is a constant, x is the input, and y is the result.

That probably isn't what you want. I would like to help, but don't quite get it Sorry...

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 4th Aug 2004 17:00 Edited at: 4th Aug 2004 17:23
Quote: "y=a^x - A is a constant, x is the input, and y is the result."


Yes - and conversely, a=y^(1/x) will enable you to convert back the other way.

That will give you a logarithmic relationship. A 'natural' logarithmic relationship is given if you use a = 'e' which is 2.718.

Probably.
Calculus
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location: Earth
Posted: 5th Aug 2004 05:00
I think this is easier said than done due to DBC's lack of a log or ln function. The code below is an example to show a rough way around this although maybe you should consider a maths dll to simplify the calculation. Unless we need exact values, an approximation would suffice for games. Maybe I could probably provide a rough polynomial to match this function within certain limits depending on the situation.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Aug 2004 08:05 Edited at: 5th Aug 2004 08:11
Not sure why you'd need the log function - can't you just use y=a^x as mentioned above? For example:


It's a bit of a rush job - but I think that's what a logarithmic scale is.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Aug 2004 09:37
Thanks everyone for posting...

As for the actual logarithm function, I am using an optimized dual function for calculating them using six terms per loop;



The first operation was originally writting as a Base-N function, which I locked to base 10 for my purposes.

Now, as for the scale -- well, I'm going to give in and do it by brute force. The trouble may be that I want to reproduce the "wrong side" of the scale given the expotential nature of the operation, that is to say that 1.1, 1.2, etc., stuff I mentioned. So far, by any means I can think of it, it occurs to me that I will need data statements to provide the proper exponents in a row to create the scale, converting back from the slider position using the log operations available.

Thanks for the effort, but I guess there is no easy way around this one.
S.

Any truly great code should be indisguishable from magic.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Aug 2004 11:07 Edited at: 5th Aug 2004 12:43
Oops - my code for the scale was wrong.

Hey - I'm not giving up that easily - this is a good learning execise for me!!

I'm beginning to understand more clearly the problem now of making the fine lines - I'll try using your log function - I'll post it when (or if) I manage to do it!
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th Aug 2004 12:31 Edited at: 5th Aug 2004 12:33
Okay, try this ...



Although it's now stuck to base 10. As I've never used functions before, I'm not sure how you assign a variable so that it is recognised inside the function as well as outside of it - is there some kind of 'global variable' command?

Anyway, I hope that is what you were after.

Richard
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 5th Aug 2004 22:59
Yeah, use the words

GLOBAL <variable>

in DB Pro and use

DIM <Variable>(0)

for DBC to make values global.

As for the code Ric, thanks... I'll give it a look see and let you know, maybe between the two of us or more folks we can work this out. And it don't matter if it's locked to base 10 for now, that's the least of the troubles.

And yeah, I agree with you about "not giving up," but after beating your head against the bricks for just so long, the headache become too great.

Thanks again, will let ya know...
Sandra.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Aug 2004 00:20
Well Ric, it seems I can't use that code for some reason. It never displays anything, and gives a divide by zero warning in the log routine because (don't ask me why) the value being passed to log() is -1. [The log routines are made to be positive values only.]

It's all very confusing to me, I have no idea what's going on.
S.

Any truly great code should be indisguishable from magic.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 6th Aug 2004 03:57 Edited at: 6th Aug 2004 04:00
Hmmm....that's odd - it works on mine. I'm using DBPro btw - I just realised you're using DBC. Anyway, I've added the 'abs' operator into the code where the logs are taken to prevent negative logs being taken and divisions by 0. Dont know if that solves the problem.........perhaps someone else knows how to translate from dbp to dbc.

Calculus
20
Years of Service
User Offline
Joined: 22nd Feb 2004
Location: Earth
Posted: 6th Aug 2004 05:44
Apologies for my solution in the source box. I thought you wanted a log scale as shown on a slide rule. I think you only need to add one for each zero:- log(3)=0.477, log(30)=1.477, log(300)=2.477 for larger numbers.

That aside, here is the DBC solution to ric's code.

Notes:
DBC dislikes the comments at the end of lines.
DBC is extremely slow at using floats in 'for loops' and so I have converted them with an extra variable where necessary or used abs.
Sync rate 0 added to speed it up as DBC fps default is set to 40.



Kind Regards
Calculus
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 6th Aug 2004 13:54
Thanks Calculus,

but I think that DBC also is having trouble with passing the float around in the FOR-NEXT loop. I already tried adding an abs function to the log routine itself, but it didn't work.

As for adding of one to each exponent, that will produce too large a scale since I do indeed desire a scale similar to that of a slide rule. If that's the case, the values will go up by powers of ten, which causes more problems in the scale desired. (Though I may look into adding some smaller values together.)

That's why I keep thinking that a data statement or two containing the exponents for the desired tick marks seems the way to go, this has been making me nuts for a long time.

S.

Any truly great code should be indisguishable from magic.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 7th Aug 2004 07:00
Well, I think I've reached the end of the road on this one - I downloaded the trial of DBC just to see what was happening, and realised that if you turn every real number into an integer by removing all of the #'s, then it actually works in principle (although pretty useless due to the extreme rounding - the slider jumps up in huge steps). But it does prove that it's not the program logic, but the problem with using real numbers in for next loops as you both suggested. The only solution left I can think of is to download at least the trial of dbpro and condider upgrading. It's working pretty nicely in dbp - I also added very simple routine to change the scale in real time by the way once I realised how global variables were defined (yeah - ok - GLOBAL(variable) wasn't to much to learn!)



Sorry I can't help more.

Richard
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 7th Aug 2004 09:38
That's okay Ric, thanks for all your effort... it's appreciated. Calculus gave me the formula I needed/wanted in the second thread about this issue, when the #IND error came up from your code in my DBC. Now I have what I needed, the process to build the scale, so I can move on...

Thanks Again.
Sandra

Any truly great code should be indisguishable from magic.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 9th Aug 2004 10:07 Edited at: 9th Aug 2004 10:41
I hate giving up! I think this works now. I thought if for-next loops don't like floats, then I'd do it with good old fashioned goto loops. You can see from the fact that the numbered labels are all over the place that I haven't used them much before.

The scale does change with the up and down arrows, but the fine lines only show in the correct places now if it is in base 10 - on account of the fact that I couldn't seem to make a# global - I tried dim a#(0) but it was still returning a divide by 0 error when it got to the function. The slider, though, still shows the correct value when the scale is altered because it's not using the log function.

I'm still not sure if this is along the lines of what you need, but I did learn a lot out of it nevertheless! (In particular, the fact that for some reason DBC doesn't like the number 4 as a goto label. 3's ok, so's 5 - but not 4 !!!)



Login to post a reply

Server time is: 2024-11-27 04:50:16
Your offset time is: 2024-11-27 04:50:16