how I can draw line of specific length in cm using C++

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2871 Views - Last Post: 08 October 2012 - 07:42 AM Rate Topic: -----

#1 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 09:47 AM

Hi
I want to code program for pattern making using C++ and QT within it but I have problem that I need to draw the pattern lines by specifying the length in cm not just x,y points can you
tell me how I can do this ??

Thanks a lot

This post has been edited by Hooor: 29 September 2012 - 09:49 AM

Is This A Good Question/Topic? 0
  • +

Replies To: how I can draw line of specific length in cm using C++

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1167
  • View blog
  • Posts: 7,213
  • Joined: 07-September 06

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 09:55 AM

With math, but what math really depends on how you want to measure cm. Do you want the cm to be based on real-world distance? Are you going to print this out on a piece of paper? Or are you going to simply display it on a screen?

The more information about what you are actually trying to accomplish the more likely we will be able to actually give you useful information.
Was This Post Helpful? 0
  • +
  • -

#3 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 10:18 AM

I want it to be printed in pieces of paper and cut fabric on it
to make clothes. so I need real world distance.

but in the screen I want something like zoom out to make it look better
and let the user see the whole pattern.

thanks a lot
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3622
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 10:27 AM

With the Windows API, you can change mapping modes of the coordinates to MM_HIMETRIC or MM_LOMETRIC: 0.01mm and 0.1mm resolution respectively. Assuming you have a good printer driver then you don't need to do anything extra. If you have a bad driver, then you should give the user an option to do some scaling in both the X and Y axis to adjust.

The question, though, is whether Qt exposes the Windows API mapping mode so that you can take advantage of the capability.
Was This Post Helpful? 0
  • +
  • -

#5 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 11:03 AM

sorry I do not know about this modes.. is it part of the C++ or some library
I have to install ??

and if I use it when I say painter.drawRect(x, y, h, w);
would it draw the shape in mm ??

Thanks a lot
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 11:21 AM

Measurements are in pixels. Well, it depends on the API.

The width or height of 500 pixels depends on the device. It's going to be different from your low resolution monitor versus, say, an iPhone. You can get the display resolution (dpi or ppi) through qt, and convert inches to pixels with the DPI value. It's not going to be perfect, but should be reasonably to scale with that mechanism.
Was This Post Helpful? 0
  • +
  • -

#7 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 11:41 AM

when I search about DPI and PPI I understand that the size changes in the printing only.
but I want to draw it from the beginning with the sizes that I want ;in cm; not just increase its size in printing because the increasing only would not give me
accurate pattern measures as I want

Is there any way to do that
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3622
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 12:24 PM

Yes, you can. If you subscribe to the MVC pattern, you follow a very strict discipline where your Model is always in the units that you want to use. You then have two different Views: a Screen View for rendering on screen, and a Printer View for rendering to the printer. Obviously, each view needs to convert from the Model's units to the appropriate device units.

Your data will always be accurate, the question will be how accurate your renderers in the Views are going to be. If you don't trust the built in APIs to do your basic shapes, you can always implement your own because the algorithms for lines, circles, arcs, and curves are well known and published.

And if you don't want to be worried about the DPI and PPI conversions, as I said, use the Windows mapping modes so that all your coordinates are already in units that are relatively compatible. Windows will do the PPI conversion when rendering on screen, and the DPI conversions when rendering to the printer.

All you need is the Windows SDK.

This post has been edited by Skydiver: 29 September 2012 - 12:21 PM

Was This Post Helpful? 1
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 01:58 PM

Quote

when I search about DPI and PPI I understand that the size changes in the printing only.
You're not understanding. DPI and PPI are device to real world unit conversions. If you have something that is 500 pixels wide, changing the DPI doesn't change how many pixels it takes up. However, the equivalent real world unit representation does change. That's the definition of this conversion factor, yes?

And what are you asking here? You want to guarantee that you draw something to scale in real world units. That means you need to convert appropriately. Which brings DPI into play.

Quote

but I want to draw it from the beginning with the sizes that I want ;in cm
I understand that. But your device (monitor) doesn't deal with cm or m or whatever. Do you understand that your display consistents of pixels? If you do, then you should realize that on the computer, you measure in pixels. So you have to convert.
Was This Post Helpful? 2
  • +
  • -

#10 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 29 September 2012 - 03:28 PM

I understand that it should be in pixels but I thought there is
any way to use cm; in easiest way. maybe it is hard to me to understand your idea in DPI cause I did not use it before . so, I will do more search about it and see what I got.


Thanks for all of you
Was This Post Helpful? 0
  • +
  • -

#11 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 30 September 2012 - 03:56 AM

would you have any links that explain how I can use these modes
because all what I have found is general description about it

Thanks
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3622
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: how I can draw line of specific length in cm using C++

Posted 30 September 2012 - 06:54 AM

I highly recommend getting a copy of Charles Petzold's Programming Windows (5th Edition):
http://www.amazon.co...s/dp/157231995X

In the meantime, this may help: http://flylib.com/bo...n/4.267.1.25/1/
Was This Post Helpful? 1
  • +
  • -

#13 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 30 September 2012 - 07:31 AM

I spent the whole day searching without any results
thanks I will see it
Was This Post Helpful? 0
  • +
  • -

#14 Hooor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 86
  • Joined: 26-May 11

Re: how I can draw line of specific length in cm using C++

Posted 07 October 2012 - 07:26 AM

I have one more question

can I draw the shapes first without using the set map mode then use the set map mode only in the printing process to get the real measures

I just want to be sure before I did it in this way

This post has been edited by Hooor: 07 October 2012 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#15 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 810
  • View blog
  • Posts: 2,407
  • Joined: 20-March 10

Re: how I can draw line of specific length in cm using C++

Posted 07 October 2012 - 05:27 PM

Hi,

No for this I would also set your mapmode for the screen as well
it makes for transforming between device contexts easier.

Also its very important to set your graphics mode to GM_ADVANCED.

ie.

SetGraphicsMode(GM_ADVANCED);

this makes transformations real world between devices ie screen and printer.

Best Wishes

Snoopy.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2