![]() |
|
#1
|
|||
|
|||
Line lengthCan anyone help?? I am trying to measure the length of a line drawn using c++ between two points. does anyone know an easy way of doing this?/ The result needs to be in centimeters and pixels.
|
|||
|
#2
|
|||
|
|||
|
Quote:
If (x1, y1) are the Cartesian coordinates of point number 1 and (x2, y2) are the Cartesian coordinates of point number 2, then the distance between them is given by the following expression (according to the Pythagorean Theorem): CPP / C++ / C Code:
The result is in the same units as the coordinates: pixels, cm, fathoms, furlongs, etc. Regards, Dave |
|
#3
|
|||
|
|||
|
Thanks very much!! I dont know whether you know if there is an easy way to convert pixels to centimeters, or is this not possible??
|
|
#4
|
|||
|
|||
|
Quote:
You can't convert values expressed in one unit system to another without knowing a scale factor that connects the systems. You keep asking for an "easy way". I don't know how "easy" it is, but there's always a way (assuming you have defined your terms precisely, and that you have enough information to determine a scale factor). If by "pixels" you mean the dots on a screen, then you must know the screen resolution, usually expressed (in the U.S. at least) in DPI (dots-per-inch). If by "pixels" you mean dots printed by an inkjet printer, then you must know the print resolution, say, in DPI. So, for a screen that is 15 inches wide and is operating with a resolution of 1024x768, the DPI can be found by: ScreenDPI = 1024/15 ~ 68.2 dots/inch Then a line that is, say, 35 pixels long (from the Pythagorean formula, using x,y coordinates expressed in screen pixels) will have the following length on screen: LengthInInches = NumberOfDots / DotsPerInch LengthInInches = 35/68.2 ~ .51 inches To convert inches to centimeters: NumberOfCentimeters = NumberOfInches / NumberOfInchesPerCentimeter or NumberOfCentimeters = NumberOfInches * NumberOfCentimetersPerInch Here's a way to look at unit conversions in general. We used to call this dimensional analysis (I don't know if the expression is still used). Let #cm be the number of cm and #in be the number of inches. #cm = #in * #cm/#in where #cm/#in = 2.54 cm/inch or #cm = #in / (#in/#cm) where #in/#cm ~ .3937 inches/cm Regards, Dave |
Recent GIDBlog
Not selected for officer school by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| burning problems PLEASE PLEASE HELP | kelticeire | Computer Hardware Forum | 4 | 01-Dec-2006 15:39 |
| Having a problem | Chuckles | Computer Hardware Forum | 19 | 13-Sep-2004 12:17 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| CD Buring Failed | skanth2000 | Computer Hardware Forum | 1 | 15-Nov-2003 03:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The