Wikipedia:Reference desk/Archives/Computing/2011 April 29

= April 29 =

Detecting click on cubic curve.
I'm writing something in Java, and I'm trying to listen for when the user clicks on a cubic curve I drew. I know the points in the curve, and the point the user clicked. I'm trying to determine if they clicked by using the distance from the curve, but I got a horrible mathematical mess. I also posted on the mathematics desk (http://en.wikipedia.org/wiki/Wikipedia:Reference_desk/Mathematics#Calculating_presence_of_root), since I can't figure out the last bit. Is there a better way I could do this? KyuubiSeal (talk) 00:39, 29 April 2011 (UTC)


 * What I would do is check the display to see if any of the nearby pixels are colored. For example, if the background is white and the curve is blue, use a for loop in a for loop to check 4 or 5 pixels left, up, right, and down from the point that was clicked for the color blue. If you see blue, the click is near the curve. It is much less complicated than a mathematical solution and it doesn't care about scale - which is required to accurately test distance to a curve. -- k a i n a w &trade; 01:05, 29 April 2011 (UTC)


 * (ec) Do you need to know if they clicked exactly on the curve (that is, on a pixel which contains part of the image of the curve), or just what the nearest object is to their click ? In the latter case, you could spiral out from the selected point in a 2D plane until you encounter the first object, and then assume they meant to pick that.  Note that this approach requires a screen map which links each pixel on the screen to an object, or to blank space.  Alternatively, you could define the map with no blank space (that is, assign every pixel to the nearest object), then a click becomes simple to identify.  Since this alternative requires more work up-front, but less with each click, it would be better for a screen which isn't updated often, but is clicked frequently.  StuRat (talk) 01:10, 29 April 2011 (UTC)


 * Instead of checking distance to the curve (which is hard and requires some calculus - and a lot of CPU due to algorithmic complexity), try this instead: you know the function f(x) you used to calculate the cubic curve. You know the (x,y) position that they clicked.  So, calculate (f(x) - y) ... in other words, the error in the exactly-vertical direction ... and determine if it is "small."
 * If you want to make this more elaborate, also calculate the error in the horizontal direction, by calculating (f-1(y) - x), where f-1 is the inverse function of your cubic. Note that inverse functions of cubics can have multiple "answers" - so, code this part carefully!  (Mathematically, the inverse is not a function because some cubic functions are not injective).  This means you can have more than one result for f-1(y) - choose the closer one!
 * To be even more elaborate, estimate the distance from the curve using:
 * Let a = (f(x) - y)
 * Let b = (f-1(y) - x)
 * Distance ≈ √(a2+b2)
 * Now, this is not the true distance, which will require calculating a normal to the curve (as I said, requiring both calculus and an iterative loop). But, instead, you get an approximate distance, requiring an algorithm with constant-run-time and only a few floating-point operations.  You can determine whether you need horizontal, vertical, or combined distance-estimates based on heuristics, or by calculating a representative derivative of your cubic function in this neighborhood.  If the curve is "nearly vertical", you only really care about horizontal distance to it, and so on.
 * Also, I'd recommend Kainaw's approach, as well, if you know you're rendering in a clean environment - you've already done the work to "flag" neighboring pixels, so re-use the prior calculation work! (Re-using the saved results of previous calculation is the core of a lot of numerical algorithm optimization!)  Nimur (talk) 01:49, 29 April 2011 (UTC)
 * To use Kainaw's method, should I just get the curve a second time (it isn't recalculated every time i access it, only if the control points change) and render it on a new BufferedImage? (Also, how did you know it was blue? :O) KyuubiSeal (talk) 03:20, 29 April 2011 (UTC)


 * What are you rendering it to? If it is in any sort of awt or swing interface, you can get the color of any pixel in the frame. There are many methods, some easier and some harder - depending on exactly what you are using. Just google for "java get pixel color". There is no need to render it twice since it will be visible. As for being blue... the math department has a thing about using blue for graphs. So, I think most people think that all graphs should be blue. I purposely don't use blue when I make graphs because I like to annoy the math department as much as possible. -- k a i n a w &trade; 04:25, 29 April 2011 (UTC)


 * I'm rendering it to a JPanel, but that's not the only thing on it, so getting pixels from there would be confusing. KyuubiSeal (talk) 13:04, 29 April 2011 (UTC)


 * Then, rendering to a hidden panel or any bitmap object is a good idea. If it has the same dimensions as the JPanel, the coordinates will be same. I suggest rendering on both the visible and hidden panels at the same time. -- k a i n a w &trade; 13:14, 29 April 2011 (UTC)


 * In that above approximation to the distance use the minimum of the absolute values of a and b rather than that square root of the sum of squares. In fact you might find a bit of curve following using the tangent of the curve at the x point is quick way to find a good approximation to the nearest point. If you're taking about cubic splines rather than a cubic all bets are off! Well actually you can either solve a fifth degree equation or approximate with something similar to what I said here but it isn't the easiest thing in the world. I'm sure somebody has free code you could just use if you search around. Dmcq (talk) 14:21, 29 April 2011 (UTC)
 * Argh, cubic splines are not the same as cubic functions! With a spline, you might have no option except to curve-follow and calculate normal distances.  Nimur (talk) 14:39, 29 April 2011 (UTC)


 * The normal method is to walk along the curve in small steps, calculating the distance between each point and your target point. Trying to solve cubic equations is not worth the effort:  even if you make it work, your code won't apply to anything other than cubics.  Trying to do this with pixels is also a bad idea:  you end up having to create some extra data structures that complicate your code and don't really speed things up significantly.  One very simple speed-up trick is to work with the square of the distance rather than the distance itself, as this saves you from having to calculate square roots. Looie496 (talk) 16:09, 29 April 2011 (UTC)

Droid X and Droid 2
I asked about these devices before and I was told that, on some devices, the boot rom can be modified after applying a certain voltage to certain pins. Would this be capable with an OMAP processor? --Melab±1 &#9742; 00:51, 29 April 2011 (UTC)

Video Chat plus pan/tilt/zoom
My google-fu has failed me. I am looking for the cheapest way possible to allow a friend to telepresence at my gaming table. I can buy a web-cam easy enough, with pan/tilt/zoom capability, plus audio. What I can't seem to find is any camera that comes with software or a remote server that would let someone remotely manipulate the camera. I have found some very expensive security cameras that supply a remote server, but they do not support pan/tilt/zoom. Any suggestions? Tdjewell (talk) 12:23, 29 April 2011 (UTC)


 * I have only seen that sort of system developed specifically for the applications in which it is used. It is not an off-the-shelf product. My favorite was developed on top of Lego Mindstorm. Not only could people on the web move the camera, they could also drive around a little car that the camera was mounted on top of. -- k a i n a w &trade; 12:25, 29 April 2011 (UTC)


 * I've used Polycom PVX for teleconferencing, and it lets you do all of those things with the cameras at either end. It might be out of your price range ($120 or so), but perhaps by searching for related products you can find something that does the same thing. You can also download a free trial of Polycom, which will let you make short video calls just to confirm it works with your camera before purchasing, which is a plus. --Mr.98 (talk) 12:40, 29 April 2011 (UTC)


 * Let your friend use Remote Desktop Connection (or whatever the Linux/Mac equivalent is called) into the PC that the webcam is connected to? Then he could use that connection to control the camera, while his locally run chat client would show him the feed. (not sure I understood the problem correctly, but if I did, this should work). Jørgen (talk) 13:56, 29 April 2011 (UTC)

bios refuses to reset in my old pc
My Intel GLLy845 mobo Pentium 4 pc was working smoothly until it suddenly froze. Not even bios was functional. However, I noticed that if I left the PC cold for more than 12 hours the bios is working. I assume that the problem is with the hdd. It even launched WinXP when I tried an old hdd on it. But one failed attempt means no response for next 12 hours or more. I used the jumper setting to remove passwords in the BIOS. But that also doesn't work. Removing Bios disk battery never worked. Why is this so? How can i 'discharge' the board so that BIOS is again functional without the 12 hour gap? I am thinking about replacing the probably dead IDE hdd with a SATA HDD and IDE to SATA converter. --117.253.191.236 (talk) 12:29, 29 April 2011 (UTC)
 * I'm fairly confused by why you think or even what you mean by your BIOS isn't working. Do you mean your computer isn't POSTing? If so are you getting error beeps? (Or do you never even normally get a POST beep in which case you're kind of SOL in diagnosing what's going on without a POST card or connecting an internal speaker and making sure it works somehow.) That being the case, I don't see any reason to think the BIOS has anything to do with the current problems. It could be a large variety of things like any parts of the motherboard (chipset, leaky caps), the RAM the processor. In theory it should give error beeps (if it normally gives a POST beep) which would suggest something to do with the motherboard but I would recommend you at least unplug all non essential items including the RAM and the all cards including any video card to test (it won't POST but I can imagine it being possible in unusual cases when despite the RAM or video card or whatever being the problem it doesn't give POST beeps). (You should of course have already unplugged all items that aren't needed to POST including the hard disk and any cards other the a video card.)
 * Also how sure are you about this 12 hour thing. Do you mean you've tried it multiple times and each time if it fails you have to wait about 12 hours before it will work (if it only happened once or twice it could be just a coincidence). If you're sure about this 12 hour thing I presume you're also sure it's nothing to do with say a fuse in the PSU, for example fans work and optical drives can open even when it doesn't POST (or whatever). If my presumption is correct my guess is that more likely (assuming there's no other fuse but I can't imagine where there would be) then having to reset the bios (whatever you mean by that) some component is heating up and causing start problems.
 * I am somewhat confused about how the HDD came in to it at all. Are you saying your HDD doesn't work in a different computer? Given the problems with the current one, I wouldn't trust it to help you determine if there are any problems with the HDD although it's not entirely clear to me what problems you even encounter with the HDD on this computer. Do note if you unplug the HDD the computer should POST fine. P.S. For a system that old there are various possible hard disk size limitations you should be aware of.
 * Nil Einne (talk) 14:51, 29 April 2011 (UTC)


 * I agree with Nil Einne that your diagnoses seem a little off, and you should back up a few steps. If your computer does not display the POST screen then this is a problem with the motherboard or something connected to it (I'm thinking of RAM sticks not properly seated) and not with the hard disk.  Try disconnecting the hard disk entirely and try a series of power-ups.  If you get the same problem with the POST screen not appearing, then you have a motherboard problem.  Comet Tuttle (talk) 20:19, 29 April 2011 (UTC)
 * I am the OP. I was not able to post here because of a Firewall problem. This is how I stand now. When I switch on the computer the fan works, and the hdd is making sounds but keyboard, monitor etc are not recognised. Keyboard shows the initial blinking but nothing follows. So, it fails in POST. However, if I try next day (about 12 hours after the failed attempts) there is a BIOS beep if the HDD is disconnected. but with the HDD connected it just stays the way I described above. So, I guessed the HDD might be the original cause of boot and POST failure. But I can't understand why it is not posting even when I remove all peripherals but would post occasionally when I try next day. When it posts it beeps but no error beep or anything at all when it the POST fails invariably. --Bluesdatum (talk) 09:24, 1 May 2011 (UTC)
 * I suspect a power supply unit problem. Very eratic behavior because of bad/leaky capacitors is my best guess. Bad capacitors are the only components I can think of that could slighty recover after hours. I suspect the hdd thing is just a side effect. 93.95.251.162 (talk) 15:04, 3 May 2011 (UTC) Martin.

cannot sign in to mail or post at this forum
I am on Wimax connection. I am not able to sign in to Gmail (gtalk works), Facebook etc. Even an attempt to register at opendns website failed. Can't even post a question at this RD normally. I succeeded after many tries. My OS is WinXP and I usually keep Window's own Firewall closed and Sygate Personal Firewall open. I fumbled with the Firewall settings but that doesnt' seem to be the problem. What could be the reason? (On rare occasions I am able to sign in to Gmail and Facebook. But even then I have problem loading pages.)--117.253.191.236 (talk) 12:36, 29 April 2011 (UTC)


 * You didn't succeed posting here after many tries. You succeeded in posting the same question many times in each of many tries. I deleted all the repeat questions. -- k a i n a w &trade; 13:16, 29 April 2011 (UTC)


 * You could be reloading the stale copy of the sign-in page from your browser's cache. First purge this page from your cache by going to http://en.wikipedia.org/w/index.php?title=Wikipedia%3AReference_desk%2FComputing&action=purge - so that you don't end up posting the same question/reply multiple times. Then purge your entire cache, and see if that fixes the problem. Rocketshiporion ♫ 01:28, 30 April 2011 (UTC)
 * I am the OP. I was not able to edit without an account. So, I created this ID. The problem is fixed. It was a Sygate Personal Firewall gone awry. It was running in the background even when disabled and was hindering traffic. I uninstalled it. Bluesdatum (talk) 09:22, 1 May 2011 (UTC)

Encrypting a database file
Hi. I asked a question regarding sqlite and java a few days back, thanks for answering it. It was very helpful. However, I now have another problem. Since SQLite database doesn't have any username/password, anybody can access it. I want to encrypt the contents of this file to prevent sensitive information being compromised (I don't want to encrypt the entire file, since that would leave all the contents unprotected when the program is accessing it - I'm looking to encrypt the actual contents). I thought about using a hash function, but that was stupid since I wouldn't be able to read it back again :) Is there a way to achieve this using java with sqlite? 122.255.9.229 (talk) 14:46, 29 April 2011 (UTC)


 * You can encrypt values before putting them into the database (probably using a symmetric cipher from javax.crypto. There's a tutorial at www.wikijava.org/wiki/Secret_Key_Cryptography_Tutorial . But remember that in doing so you defeat some of the utility in having a database, as you can no longer use the contents of those, now encrypted, fields in the WHERE section of a SELECT query, and you can't ORDER BY them either. Of course this still leaves the problem of where you'll keep the secret key; it's too big for most people to remember. -- Finlay McWalter ☻ Talk 15:56, 29 April 2011 (UTC)


 * Or you could create a small encrypted filesystem and keep the database files in there. That way the java code need know nothing about cryptograpy or secrets. And the whole database (including the schema) is encrypted, not just the values. You'd write a wrapper script around your java program to mount and unmount the EFS, and you still need to store the secret key or passphrase somewhere. -- Finlay McWalter ☻ Talk 16:00, 29 April 2011 (UTC)


 * You could use hash functions, incidentally, but only for limited applications. Imagine you had a database where the data itself was always encrypted as individual fields, but you wanted to be able to search for exact matches on a given field (like a last name). What you could do is have one extra, unencrypted field that was a case-insensitive hash of the field you wanted to be able to search by, and then you could search for the hash at runtime, without decrypting the database at all. This would allow a potential attacker/snooper to see if there was an entry in the database for a given name, but, barring rainbow table attacks, they wouldn't be able to actually figure out the total list of names. And in either case, they wouldn't be able to decrypt the presumably more sensitive data. Anyway, it's not the best scheme, but it came to mind while I read your post. It would have very limited applicability, obviously, since hash matching would only occur if there were exact matches. --Mr.98 (talk) 20:50, 2 May 2011 (UTC)

Wifi antenna
Can I buy an extra antenna for a computer? I have interest in something with a range of 1 mile, at a reasonable price. Quest09 (talk) 17:20, 29 April 2011 (UTC)


 * At that range you'll need a highly directional antenna. A Google search for "directional wifi antenna" should find many options in you region. Some folks build them themselves - see cantenna. -- Finlay McWalter ☻ Talk 17:26, 29 April 2011 (UTC)


 * And you need a wifi card that allows for the antenna to be replaced (usually by unscrewing a co-axial connector and running a cable to the new antenna). As the high directionality of the antenna means that even a small deflection of it from its intended direction will mean it'll lose signal, you'll probably need a robust bracket to hold it firmly in place. -- Finlay McWalter ☻ Talk 17:32, 29 April 2011 (UTC)


 * Thanks so far. And then, what is the maximum range of a non-directional antenna? One that would work like a normal standard wifi antenna. Quest09 (talk) 17:57, 29 April 2011 (UTC)


 * Omni-directional antennas, of the type supplied with most wifi equipment, are intended for internal use (where the signal bounces around unpredictably off stuff in the house or office); the actual performance you'll get will vary hugely with the features of the building. Outside, in a straight line, you might get 100m if you're very lucky. Note that you can also get external omnidirectional antennas intended for providing wifi to an area like a garden or campus, which should perform better. -- Finlay McWalter ☻ Talk 18:22, 29 April 2011 (UTC)


 * After upgrading your antenna, you can also boost the power by adding an external power-amplifier, though this circumvents FCC rules and can get you in trouble. (Remember - if you're broadcasting radio signals, they know how to find you!)  If it turns out your homebrew radio is screwing up other people's electronics, you can get into "trouble."
 * So, you want 1-mile IP traffic? Consider AX.25, a wireless radio protocol that can provide the physical layer for IP traffic.  You can get an amateur radio license and broadcast AX.25 data.  I've heard guys from TAPR from 25 or 30 miles on VHF links.  (They spend a lot of money on radio gear, though).
 * Unfortunately, the truth is that as you start getting in to the long-range radio, you will start needing to become cognizant of "technical details" that you can generally ignore for short-range, indoor "wifi"- and "bluetooth"-style wireless data. Multipath interference; analog signal properties; and signal loss, error-rate, and coding technology that you don't even think about in omnidirectional 802.11 radio will start to become much more important when your wireless signal path is a mile long.  Nimur (talk) 18:53, 29 April 2011 (UTC)


 * Our cantenna article doesn't discuss the range improvements, oddly, but the external links in that article may be useful. Comet Tuttle (talk) 20:15, 29 April 2011 (UTC)

When good electricity meters go bad
Our external house meter is no longer turning, but we still have power, which seems like an odd combo. We recently had to disconnect one leg of the power drop, because it had started arcing at the connector. Could only having one leg connected create an imbalance and cause this type of malfunction ? Bear in mind that the single leg is now powering the entire house, whereas it was only used for half the house before. Could we have exceeded the amp rating of the meter (and what is the rating, anyway) ? We are only using one meter now, as opposed to two previously. Here are the markings on the meter:

FM 2S CL 200 240V TYPE: OMRMX TA 30 Kh 7.2 3W 60Hz

Thanks. StuRat (talk) 18:14, 29 April 2011 (UTC)


 * I take it we are talking about a split phase and not two phase. Did you disconnect the neutral? This might be considered tampering by the utility company. --Aspro (talk) 18:54, 29 April 2011 (UTC)


 * How can we tell the difference between "split phase" and "two phase" ? I don't believe the neutral was disconnected.  If it was inadvertently disconnected, would this cause the meter to fail, yet still allow power through ? StuRat (talk) 19:41, 29 April 2011 (UTC)


 * I suggest you just call the electric company. They will want to replace the meter anyway (a malfunctioning meter cuts into their profit margin), and they are trained and equipped to deal with the materials.  Keep in mind that if this is the main line coming into your house, you can get a heck of a nasty shock off it (much worse than sticking your finger in a socket).  -- Ludwigs 2  10:05, 1 May 2011 (UTC)


 * I don't know about your electricity company, but in the UK the electricity company generally takes an extermely dim view of tampering with the supply. Even if you consider yourself innocent of tampering, they might suspect you all the same - there are many people out there looking to commit fraud against the electricty company and they may be more prepared to think that was your aim too, rather than you protecting yourself from a potential fire.  I easily found these two articles indicating hefty fines and possible jail time.  I suggest you call the electricity company's emergency line immediately.  Astronaut (talk) 11:24, 1 May 2011 (UTC)

UPDATE: We now switched to the other meter, and it has stopped working, too. So it's looking more like having only one leg connected causes the problem. Does anybody have any insight other than "call the electric company" ? StuRat (talk) 16:18, 4 May 2011 (UTC)

eFuse programming
Can an eFuse be reprogrammed? --Melab±1 &#9742; 21:28, 29 April 2011 (UTC)
 * Are you speaking generically about a programmable logic device, or are you referring specifically to eFUSE from IBM? In general, programmable silicon devices that are called "fuses" are PROM (one-time-programmable); but there are EEPROM and other field-programmable logic devices.  Lots of engineers abuse terminology, and call anything that writes to a non-volatile silicon storage "fusing."  The long and short of it is, "depends on the device," and who-ever called it a fuse needs to specify more detail.  Nimur (talk) 21:57, 29 April 2011 (UTC)
 * eFUSE from IBM as used in the OMAP processors in the Droid X, Droid 2, and Droid 2 Global. --Melab±1 &#9742; 02:00, 30 April 2011 (UTC)
 * TI has a page on OMAP Security, including this white paper, M-Shield™ Mobile Security Technology, which states that their "E-Fuse" is a one-time programmable device. So, it can't be "reset," it is electrically burned and physically exists on the chip.  This fascinating archive-scan from 1988 gives you the electrical properties of the Texas Instruments fuses on a certain family of devices.  (.... from 1988).  Here's a nice academic paper with some electron-micrographs of what a generic "fuse" actually looks like: Blowing of polycrystalline silicon fuses - a modern TI chip probably uses something like that, but much smaller, for on-chip PROM.  Nimur (talk) 15:21, 30 April 2011 (UTC)
 * I understand now. There was a lot of talk about how eFUSEs were responsible for making the Droid X and Droid 2 only run signed code. But can't this be done without eFUSEs, like the iPhone does? I was also thinking that I could bypass this by ordering a custom OMAP3630. Despite me not being a high-volume OEM/ODM, would there be incompatibility issues if I swapped out the OMAP3630 in a Droid X with one that does not check signatures? --Melab±1 &#9742; 16:16, 1 May 2011 (UTC)
 * Unless you have detailed schematics of the Droid X, it's difficult to say with certainty whether you can just "swap out" the OMAP chip with an stock part you buy at Digikey or TI. The production chip might speak encrypted protocols to all its connected peripherals; it might even have a non-standard pin-out. (Do you even have the equipment to do this type of electrical work?  BGA chip removal isn't trivial.  You'll need a surface-mount chip reflow system, some high-quality tweezers, a BGA solder-mask maker, and a very steady hand).  Why don't you buy an OMAP engineering prototype board instead?  Those boards are intentionally designed for you to develop on; they expose electrical test-points; the CPUs are configured without code-signing; some are as cheap as $174 - less than your PC probably cost, and probably with a more powerful CPU!  A form-factor unit is also available for $1999, BLAZE Pico.  It's pretty much the same hardware as a $174 PandaBoard, but looks more "phone-like."
 * That's what I was worried about. --Melab±1 &#9742; 21:44, 1 May 2011 (UTC)
 * Here's another dev kit for $149 - BeagleBoard OMAP dev kit. It can even run Ubuntu if you don't like writing your own operating system, or working within the constraints of a commercial operating system.  Nimur (talk) 19:25, 1 May 2011 (UTC)
 * Well, the Droid X and the Droid 2 use the Texas Instruments OMAP3630 processor. --Melab±1 &#9742; 21:46, 1 May 2011 (UTC)
 * An OMAP3630 from a GSM device work in a CDMA device? --Melab±1 &#9742; 21:57, 1 May 2011 (UTC)

Loosely speaking, an OMAP is a CPU (it is actually more than that, but I'll try to make the analogy to conventional PC hardware). The CPU only runs software and does not have a radio. On a PC, you typically have a separate WiFi chip that contains the radio circuitry and a small amount of logic and/or software. The equivalent in a mobile phone is a radio chip, which contains the radio(s) and a small amount of logic and/or software. The OMAP is just the application processor (CPU), so it doesn't know about radio protocols or signal characteristics. It just sends data to the radio chip, who then translates to either GSM or CDMA or AX.25 or 802.11 ... or whatever. This is similar to how an Intel CPU is agnostic about whether it sends data via WiFi or BlueTooth or serial port. Now, your major manufacturers might choose a different OMAP for the GSM and CDMA models, just like a PC maker might put a different CPU in each of their PC models, but the OMAP will not have any specialization for CDMA or GSM. Finally, as you seem to want to develop mobile phone systems, keep in mind that you can't muck with radio chips "casually," because it necessarily also mucks with other people's equipment. (Your mobile phone company and the FCC will come screaming if they find out you've been 'debugging' GSM on their frequency. So unfortunately, there isn't much room in the world for the hobbyist GSM developer.  If you want to work with radios, you need to get in touch with a system designer who has a special agreement with the carrier, and has all the arrangements with the FCC, and usually will have a big test lab isolated from the rest of the world.  (Remember - your mobile data device has a very powerful radio that transmits an omnidirectional signal with a range of many miles and if you screw up, everyone in range can be affected).  Plus, you will need a development kit for a radio chip, not an application processor like OMAP.  If this is unsatisfactory, you should consider a different radio band, such as an Amateur Radio frequency, and obtain a license for transmitting data. There are lots of tools to support such an effort. Nimur (talk) 00:13, 2 May 2011 (UTC)