2013-05-05 4 views
0

Qt의 픽스맵에서 "도로"를 그리는 데 정말로 어려움이 있습니다. 저는 서로 매우 가까운 분수 값으로 모든 좌표를가집니다 (저는 Mercator의 수식을 사용하여 경도/위도를 X/Y 좌표로 변환하지 못했습니다). Qt drawLine 함수는 픽스맵에 그리는 정수 매개 변수만을 가지고 있습니다 (아무도 2.5 픽셀을 그리지 않을 것입니다).픽스맵에 도로 (선)를 그리는 방법

Xold = x 
Ynew = Ymax - Y 

가 지금은 보통 X가/Y 좌표 시스템을 가지고, Y 축 상단에 갈과 X 축이 왼쪽으로가는 : 또한, 그래서 나는 다음과 같이 변경해야하는 왼쪽 상단에 시작 좌표 . 여기

내가 선 그릴려고 얼마나 내 코드입니다 : 최대한 빨리 그들이 정수와 모든 잘못로 변환 drawLine 기능에 x1, y1, x2, y2를 넣어하지만

double minlat = 637800*log(tan(3.14/4+3.14*bounds[1]/360.0))/log(2.71),maxlat=637800*log(tan(3.14/4+3.14*bounds[2]/360.0))/log(2.71); 
    std::vector<double> x; 
    std::vector<double> y; 
    QSize size = ui->label_2->size(); 
    size=ui->label_2->size(); 
    QImage pic(size.width(),size.height(),QImage::Format_ARGB32_Premultiplied); 
    pic.fill(Qt::transparent); 
    QPainter painter(&pic); 
    for (unsigned int i=0; i < wayVector.size(); i++){ 
     for (unsigned int j=0; j<wayVector[i].refs.size(); j++){ 
      x.push_back(637800*3.14*nodeHash[wayVector[i].refs[j]].lon/180.0); 
      y.push_back(637800*log(tan(3.14/4+3.14*nodeHash[wayVector[i].refs[j]].lat/360.0))/log(2.71)); 

     } 
     for (unsigned int j=0; j<wayVector[i].refs.size()-1;j++){ 
      painter.setPen(Qt::green); 
      double x1 = x[j]/(size.width()/(maxlon-minlon)); 
      double y1 = maxlat*size.height()/(maxlat-minlat)-y[j]*size.height()/(maxlat-minlat); 
      double x2 = x[j+1]/(size.width()/(maxlon-minlon)); 
      double y2 = maxlat*size.height()/(maxlat-minlat)-y[j+1]*size.height()/(maxlat-minlat); 
      painter.drawLine(x1,y1,x2,y2); 
     } 
     x.clear(); 
     y.clear(); 
    } 

모든 X 때문에/Y 좌표가 동일 해집니다 (매우 가깝기 때문에).

필자는 어떻게이 선을 pixmap에 그리는 지 알 수 없습니다. 아이디어가 있으십니까?

+0

그건 그렇고, 나는 Pixmap만을 사용할 필요가 없습니다. 누군가가 그것을 할 다른 방법을 보여줄 수 있습니다. 고맙습니다. – tema

답변

관련 문제