It is an algorithm question. I didn't post code to bog down. See Edit. There is an error somewhere in the process I am using to work out each colour of the pixel on the screen.
Which other forum would it belong in? I figured this would be the best place
I've had a go at moving through the pixels in half steps. This hasn't worked, but:
I am going to have a go at getting the average colour of the pixel between the half steps in an attempt to do some anti-aliasing
I'm working on a 128 bit unsigned integer class (due to Numerics.BigInt being too slow). I've gotten most of the regular arithmetic functions working, but now I'm on the Modulo one. Does anyone know of shortcuts to finding the remainder without having to go through the full division? (Yes, I have googled this for several days, with little progress)
So far the only one I've found is if the divisor is a power of 2, you can use
Remainder = Dividend & (Divisor - 1);
But that's it. Nothing for any other number. So if anyone knows of anything similar, or heck, just a really fast division/mod algorithm, please let me know.
I'm not sure this will help in your case, but it seems that eons ago I saw an algorithm that basically repeatedly bit shifted and subtracted in binary. Perhaps the Mongomery algorithm[^] would suit your purpose?
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software
128 bits isn't "really big", so the asymptotically optimal algorithms aren't a very good choice here.
For 128 bits, I think what would work best is a simple multiword division. There's lots of stuff on google, it's in one of Knuth's books, and hackers delight has some code here[^] that also explains the algorithm.
edit: yes that does a division, and you go to mod from there - I know of no general way to do a mod without a division.
Just wondering, how did you implement multiplication? I hope it's not shifts and adds.. it works, to be fair, but it's very much slower than using long multiplication in base 2^32 (or base 2^64 if you have access to a 64x64->128 multiplication)
i have created one portable application,initially it will take several time to install on to pendrive(installer doing more on dll copy option), for that i want to show time remaining in my UI.
can any one suggest me best algorithm to do this please
If you know how much data you need to install then you can set a timer to measure your install speed and use that value to estimate how much time the remainder will take. Adjust the value as you go through the install. Something like:
Total to install 1Mb
After installing 100Kb time taken is 2 seconds, so time left is ((1000 - 100) / 100 * 2) = 18 seconds
After installing 200Kb time taken is 3 seconds, so time left is ((1000 - 200 / 200 * 3) = 12
I've been implementing a PID control algorithm[^] to control a heater (or cooler) to reach a setpoint. Everything works perfectly so far - PID really is magic.
Now the device I'm using can heat or cool depending on the polarity of the voltage you apply to it, so, with a suitable relay and some hardware, I can automate it to switch from heating to cooling or vice versa. As it currently works (I have a manual switch to reverse polarity), if you have a setpoint of, let's say, 30°C, it'll heat up, overshoot, shut off the voltage and cool naturally, then undershoot and turn the voltage back on. In theory, I suppose, it could be more efficient if, instead of letting it cool naturally, I switch the polarity and drive it back down. It's more aggressive and likely to be less stable perhaps, but my real concern is that it'll abuse the heck out of the relay which will be rapidly switching back and forth around the setpoint. So I was thinking that if I have some kind of "dead zone" area to add a "buffer" around the setpoint it might save the relay. In essence, the relay should only switch if you're a long way off and not when you are right around the setpoint. I was thinking if I made my input range say, -10 to +10 and in software I mapped it such that +10 gives the maximum voltage to the device and it reduces linearly until it reaches 0 at, let's say +2. Then from +2 to -2 the voltage remains at zero, and from -2 to -10 the voltage goes up again, but the polarity is reversed.
One concern here is that in addition to stopping it switching polarity, it'll also delay turning it back on. Also, depending on where the setpoint is, I should be spending most of the time either cooling or heating. For example, if I change the setpoint from 10°C to 5°C, I should spend most of my time cooling, I really shouldn't need to heat at all unless I drastically overshoot, and I'm not sure whether this will automatically pick up on that.
Does this sound like something that might work (I'm waiting on the hardware at the moment, so I'm just thinking it through right now)? Is there a way to handle this kind of setup? Is it just a bad idea? Should I just not try and drive it so aggressively?
It's normal practice in controls to use hysteresis around a set point to prevent overworking the hardware. Even air conditioning systems use it. If you set a target of 70°F, for instance, the heating unit won't kick on until the temp drops to about 68, and won't shut down until it senses 71 - 72. This prevents constant cycling on and off, which is very important if there's a motor involved. They tend to overheat, and can be damaged by rapid cycling.
Don't try to set it to aggressively, else you might fall into a positive feedback situation, with the controlled value oscillating around, but never actually stabilizing at the setpoint. That will ead to rapid equipment failure.
Do not look so much into code - a good setup of the "hard ware" is more important.
Find a good distance for the thermometer from the heater/cooler proper. Mix the item to be heated/cooled well; if you cannot mix the items proper, mix the surrounding media (air or liquid) and do not forget that the delay will be bigger.
In the absence of any further logical constraints (i.e. emptiness of each cell is independent of other cells), brute force (checking all the cells until you find an empty one) is the only way. (On a 3×3 grid that is no problem.)
emptySpot does not work. For some reason, this function only works when I hardcode remove an Element from its Canvas. Then there is only one Canvas of the 9 that has no Element and the code picks it up.
Last Visit: 31-Dec-99 18:00 Last Update: 3-Oct-23 18:04