1

(3000.00,4500.45) のような大きな double 値を持つ線を描画する必要があります。

CImg<unsigned char> img(800,800,1,3,20);
img.draw_line( 3000.00, 4500.45, 3478.567, 4500.45, RED);

しかし、画面サイズを 800x800 に制限したい

Pointの座標のModulusを800以内にしようと思いました Like

3000.00%800=600

Screen に 600 を収めることができます。しかし問題は、CPP が double 値の係数をサポートしていないことです。

double a = 3000.00;
printf("%lf",a%800.0); //Expected 600 but exception
**Invalid operand of type double,double to binary operator%**

CImg を使用してこれらの大きなポイントを画面に収めるにはどうすればよいですか?

4

2 に答える 2

1

All depend on what you want to perform actually :

  • If you just want to see the part of the line drawn on your 800x800 image, then do nothing. The CImg<T>::draw_line() method implements clipping and it will do this automatically for you.
  • If you want to drawn "random" lines on your screen and don't care about the fact that using a modulo on your coordinates will screw up the original line appearance, then you can use a modulo. In your case, it is probably better to first cast your coordinates into int, then use the % operator afterwards :

img.draw_line( ((int)x0)%800, ((int)y0)%800, ((int)x1)%800, ((int)y1)%800, RED);

but be aware that the line that will be drawn has nothing to do with the original line: doing modulos is not a clipping method for drawing lines.

于 2013-09-13T06:49:28.373 に答える