小编Max*_*Max的帖子

创建通过所有给定点的非相交多边形

假设我有个的以随机顺序阵列,并且我需要找到一个多边形(由对它们进行排序,使得每对相邻的表示的一侧)穿过所有的点,并且其两侧是不相交的进程.

我尝试通过选择一个点,并将所有点添加到其下面的最终数组,从左到右排序.然后,添加其上方的所有点,从右到左排序.

我被告知我可以添加一个额外的点并自然排序以避免自我交叉..虽然我无法弄明白.有什么简单的方法可以做到这一点?

algorithm geometry convex-hull

22
推荐指数
5
解决办法
1万
查看次数

找到素数的位置

我需要反过来找到第N个素数,即给定素数,我需要找到它的位置

2, 3, 5, 7...
Run Code Online (Sandbox Code Playgroud)

素数可以很大,按照的顺序10^7.此外,还有很多.

我有一个可以二进制搜索的预先计算的素数索引,但我也有50k的空间限制!可以筛选吗?或者任何其他快速方式?

编辑:非常感谢所有精彩的答案,我没想到他们!我希望他们对寻找同样的人有用.

c algorithm math primes sieve

13
推荐指数
1
解决办法
3919
查看次数

gluLookAt如何工作?

根据我的理解,

gluLookAt(
        eye_x, eye_y, eye_z,
        center_x, center_y, center_z,   
        up_x, up_y, up_z
    );
Run Code Online (Sandbox Code Playgroud)

相当于:

glRotatef(B, 0.0, 0.0, 1.0);
glRotatef(A, wx, wy, wz);
glTranslatef(-eye_x, -eye_y, -eye_z);
Run Code Online (Sandbox Code Playgroud)

但是当我打印出ModelView矩阵时,调用glTranslatef()似乎不能正常工作.这是代码片段:

#include <stdlib.h>
#include <stdio.h>
#include <GL/glut.h>

#include <iomanip>
#include <iostream>
#include <string>

using namespace std;

static const int Rx = 0;
static const int Ry = 1;
static const int Rz = 2;

static const int Ux = 4;
static const int Uy = 5;
static const int Uz = 6; …
Run Code Online (Sandbox Code Playgroud)

c++ opengl viewing glulookat

6
推荐指数
1
解决办法
1万
查看次数

HoughLines在opencv中进行转换

我正在使用opencv和Eclipse进行图像处理.

  vector<Vec2f> lines;  
  HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );

  for( size_t i = 0; i < lines.size(); i++ )  
  {  
     float rho = lines[i][0], theta = lines[i][1];  
     Point pt1, pt2;  
     double a = cos(theta), b = sin(theta);  
     double x0 = a*rho, y0 = b*rho;  
     pt1.x = cvRound(x0 + 1000*(-b));  
     pt1.y = cvRound(y0 + 1000*(a));  
     pt2.x = cvRound(x0 - 1000*(-b));  
     pt2.y = cvRound(y0 - 1000*(a));  
     line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);  
  }  
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这个代码如何定义点.我们正在使用

y=(-cos(theta)/sin(theta))x + r/(sin(theta))
rho=xo*cos(theta) + …
Run Code Online (Sandbox Code Playgroud)

c++ opencv hough-transform

3
推荐指数
1
解决办法
6657
查看次数

使用JavaZOOM BasicPlayer类播放某些MP3时出错

这是堆栈跟踪:

java.io.IOException: Resetting to invalid mark
    at java.io.BufferedInputStream.reset(BufferedInputStream.java:433)
    at org.tritonus.share.sampled.file.TAudioFileReader.getAudioInputStream(TAudioFileReader.java:324)
    at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
    at javazoom.spi.mpeg.sampled.file.MpegAudioFileReader.getAudioInputStream(Unknown Source)
    at javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1179)
    at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
    at javazoom.jlgui.basicplayer.BasicPlayer.initAudioInputStream(Unknown Source)
    at javazoom.jlgui.basicplayer.BasicPlayer.open(Unknown Source)
    at BasicPlayerDemo.play(BasicPlayerDemo.java:49)
    at BasicPlayerDemo.main(BasicPlayerDemo.java:24)
Run Code Online (Sandbox Code Playgroud)

似乎其他人也有这个问题:

有什么理由吗?我正在尝试使用JavaZoom类创建一个简单的Java Swing音乐播放器.

java mp3 swing javasound ioexception

2
推荐指数
1
解决办法
2113
查看次数

glReadPixels() 返回不准确的值

我正在尝试实现洪水填充算法。但是 glReadPixels() 返回像素的浮点 RGB 值,该值与我设置的实际值略有不同,导致算法失败。为什么会发生这种情况?

输出返回的 RGB 值以进行检查。

#include<iostream>
#include<GL/glut.h>
using namespace std;

float boundaryColor[3]={0,0,0}, interiorColor[3]={0,0,0.5}, fillColor[3]={1,0,0};
float readPixel[3];

void init(void) {
    glClearColor(0,0,0.5,0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0,500,0,500);
}

void setPixel(int x,int y) {        
        glColor3fv(fillColor);
        glBegin(GL_POINTS); 
             glVertex2f(x,y); 
        glEnd();
}

void getPixel(int x, int y, float *color) {
    glReadPixels(x,y,1,1,GL_RGB,GL_FLOAT,color);
}

void floodFill(int x,int y) {
    getPixel(x,y,readPixel);

    //outputting values here to check
    cout<<readPixel[0]<<endl;
    cout<<readPixel[1]<<endl;
    cout<<readPixel[2]<<endl;

    if( readPixel[0]==interiorColor[0] && readPixel[1]==interiorColor[1] && readPixel[2]==interiorColor[2] ) {
        setPixel(x,y);
        floodFill(x+1,y);
        floodFill(x,y+1);
        floodFill(x-1,y);
        floodFill(x,y-1);
    }
}

void display() {
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3fv(boundaryColor); …
Run Code Online (Sandbox Code Playgroud)

opengl rgb glut glreadpixels

1
推荐指数
1
解决办法
1677
查看次数