参数方程绘制球面、椭球面、环面

您所在的位置:网站首页 锥面的一般方程公式 参数方程绘制球面、椭球面、环面

参数方程绘制球面、椭球面、环面

2023-09-07 14:54| 来源: 网络整理| 查看: 265

^ ^ 效果球面坐标取法关于曲面代码

效果

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

球面坐标取法

在这里插入图片描述 选用经度角的余角更为方便,绘制整个球面是0到π 用经度角绘制整个球面,是从-π/2到π/2 其实没什么差别啦 在这里插入图片描述

然后椭球面和环面同理。(书上有错~) 在这里插入图片描述

关于曲面

整个曲面是由许多小的平面组成的,这里用的是四边形。 所以只要知道这些平面的坐标,便能绘制相应的曲面。 程序里要做的是,获取球面上数个点的坐标,然后用这些坐标绘制平面。 所以不同曲面在程序中的不同,也只是取点啦。

int getPoint(GLfloat radius, GLfloat a, GLfloat b, point &p) {//半径,经度角补角a,纬度角b p.x = radius * sin(a*pi / 180.0)*cos(b*pi / 180.0); p.y = radius * sin(a*pi / 180.0)*sin(b*pi / 180.0); p.z = radius * cos(a*pi / 180.0); return 1; } int getPoint_Oval(GLfloat rx, GLfloat ry, GLfloat rz, GLfloat a, GLfloat b, point &p) {//半径,经度角补角a,纬度角b p.x = rx * sin(a*pi / 180.0)*cos(b*pi / 180.0); p.y = ry * sin(a*pi / 180.0)*sin(b*pi / 180.0); p.z = rz * cos(a*pi / 180.0); return 1; } int getPoint_Ring(GLfloat radius, GLfloat rHollow, GLfloat a, GLfloat b, point &p) {//外径,内径,经度角补角a,纬度角b p.x = (rHollow + (radius - rHollow) * sin(a*pi / 180.0))*cos(b*pi / 180.0); p.y = (rHollow + (radius - rHollow) * sin(a*pi / 180.0))*sin(b*pi / 180.0); p.z = (radius - rHollow) * cos(a*pi / 180.0); return 1; } 代码

从这里复制的代码,OpenGL 参数方程绘制球 https://blog.csdn.net/guanmjie/article/details/6369924 然后稍做修改,添加了椭球面和环面的取点函数… 懒得考虑重用了,仅有传递的参数不一样也直接复制了整个函数。

#pragma once // Windows Header Files #include // C RunTime Header Files #include #include #include #include #include #include #define pi 3.1415926 #define SOLID 3000 #define WIRE 3001 typedef int SPHERE_MODE; typedef struct Point3f { GLfloat x; GLfloat y; GLfloat z; }point; void drawSlice(point &p1, point &p2, point &p3, point &p4, SPHERE_MODE mode) {//绘制四边形 switch (mode) {//实面或网格 case SOLID: glBegin(GL_QUADS); break; case WIRE: glBegin(GL_LINE_LOOP); break; } glVertex3f(p1.x, p1.y, p1.z); glVertex3f(p2.x, p2.y, p2.z); glVertex3f(p3.x, p3.y, p3.z); glVertex3f(p4.x, p4.y, p4.z); glEnd(); } #pragma region 球面 int getPoint(GLfloat radius, GLfloat a, GLfloat b, point &p) {//半径,经度角补角a,纬度角b p.x = radius * sin(a*pi / 180.0)*cos(b*pi / 180.0); p.y = radius * sin(a*pi / 180.0)*sin(b*pi / 180.0); p.z = radius * cos(a*pi / 180.0); return 1; } point* getPointMatrix(GLfloat radius, GLint slices) { int i, j, w = 2 * slices, h = slices; float a = 0.0, b = 0.0; float hStep = 180.0 / (h - 1);//均分整个球 float wStep = 360.0 / w; int length = w * h; point *matrix; matrix = (point *)malloc(length * sizeof(point)); if (!matrix)return NULL; for (a = 0.0, i = 0; i for (j = 0; j int i, j, w = 2 * slices, h = slices; float a = 0.0, b = 0.0; float hStep = 180.0 / (h - 1); float wStep = 360.0 / w; int length = w * h; point *matrix; matrix = (point *)malloc(length * sizeof(point)); if (!matrix)return NULL; for (a = 0.0, i = 0; i for (j = 0; j int i, j, w = 2 * slices, h = slices; float a = 0.0, b = 0.0; float hStep = 180.0 / (h - 1); float wStep = 360.0 / w; int length = w * h; point *matrix; matrix = (point *)malloc(length * sizeof(point)); if (!matrix)return NULL; for (a = 0.0, i = 0; i for (j = 0; j 1.0,1.0,1.0,1.0 }; GLfloat _diffuse[] = { 1.0,1.0,1.0,1.0 }; GLfloat _specular[] = { 1.0,1.0,1.0,1.0 }; GLfloat _position[] = { 200,200,200,0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, _ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, _diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, _specular); glLightfv(GL_LIGHT0, GL_POSITION, _position); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 500, 0.0, 500, -500, 500); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void display(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glTranslated(250, 250, 0); glRotated(30, 1, 0, 0); glRotated(60, 0, 1, 0); //glRotated(90, 0, 0, 1); glColor3f(1.0, 1.0, 1.0); drawSphere(200, 20, WIRE); //drawEllipsoid(200, 100, 50, 20, WIRE); //drawRing(200, 180, 20, WIRE); glFlush(); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); glutCreateWindow("Revolution"); init(); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMainLoop(); return 0; }

从这里复制的主体代码,OpenGL 参数方程绘制球 https://blog.csdn.net/guanmjie/article/details/6369924



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3