GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Mar-2005, 09:20
dan_ielle20 dan_ielle20 is offline
New Member
 
Join Date: Mar 2005
Posts: 4
dan_ielle20 is on a distinguished road
Lightbulb

Line length


Can 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  
Old 22-Mar-2005, 09:28
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by dan_ielle20
I am trying to measure the length of a line drawn using c++ between two points.

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:
distance = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));

The result is in the same units as the coordinates: pixels, cm, fathoms, furlongs, etc.

Regards,

Dave
  #3  
Old 22-Mar-2005, 09:43
dan_ielle20 dan_ielle20 is offline
New Member
 
Join Date: Mar 2005
Posts: 4
dan_ielle20 is on a distinguished road
Smile

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  
Old 22-Mar-2005, 10:10
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by dan_ielle20
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??


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 GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 00:25.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.