📄 ellipses.cc
字号:
//**************************************************************//* filename: ellipses.cc *//* *//**************************************************************//* programmed by: Thomas Wagner *//* last change: 17-03-95 *//**************************************************************#include "ellipses.h"Ellipsis_2d::Ellipsis_2d (DMatrix * form, double centerx, double centery):Ellipsis (){ unsigned short xindex = 0, yindex = 1; center[0] = centerx; center[1] = centery; short counter; double anglestep = M_PI_2 / POINTSPERSEGMENT, tempx[POINTSPERSEGMENT], tempy[POINTSPERSEGMENT]; ellipsis = (Point_2d *) malloc (sizeof (Point_2d) * 2 * POINTSPERSEGMENT);// now calculate 1*1 circle for (counter = 0; counter < POINTSPERSEGMENT; counter++) { tempx[counter] = sin (counter * anglestep); tempy[counter] = cos (counter * anglestep); } for (counter = 0; counter < POINTSPERSEGMENT; counter++) { ellipsis[counter].x = form->Lese_i_j (xindex, xindex) * tempx[counter] + form->Lese_i_j (xindex, yindex) * tempy[counter]; ellipsis[counter].y = form->Lese_i_j (yindex, xindex) * tempx[counter] + form->Lese_i_j (yindex, yindex) * tempy[counter]; ellipsis[counter + POINTSPERSEGMENT].x = form->Lese_i_j (xindex, xindex) * tempy[counter] - form->Lese_i_j (xindex, yindex) * tempx[counter]; ellipsis[counter + POINTSPERSEGMENT].y = form->Lese_i_j (yindex, xindex) * tempy[counter] - form->Lese_i_j (yindex, yindex) * tempx[counter]; }}void Ellipsis_2d::DrawMe (Output2d_3d * window, Drawable drawable){ XPoint points[4 * POINTSPERSEGMENT + 1]; short pointcounter, offset = 2 * POINTSPERSEGMENT; for (pointcounter = 0; pointcounter < 2 * POINTSPERSEGMENT; pointcounter++) { window->WorldtoPixel2d (center[0] + ellipsis[pointcounter].x, center[1] + ellipsis[pointcounter].y, &(points[pointcounter].x), &(points[pointcounter].y)); window->WorldtoPixel2d (center[0] - ellipsis[pointcounter].x, center[1] - ellipsis[pointcounter].y, &(points[pointcounter + offset].x), &(points[pointcounter + offset].y)); } points[pointcounter + offset].x = points[0].x; points[pointcounter + offset].y = points[0].y; XDrawLines (window->Getdisplay (), drawable, window->Getgc (), points, 4 * POINTSPERSEGMENT + 1, CoordModeOrigin);}Ellipsis_2d::~Ellipsis_2d (){ free (ellipsis);}Ellipsis_3d::Ellipsis_3d (DMatrix * form, double centerx, double centery, double centerz):Ellipsis (){ unsigned short xindex = 0, yindex = 1, zindex = 2; center[0] = centerx; center[1] = centery; center[2] = centerz; short counter; double anglestep = M_PI_2 / POINTSPERSEGMENT, tempx[POINTSPERSEGMENT], tempy[POINTSPERSEGMENT]; ellipsis[0] = (Point_3d *) malloc (sizeof (Point_3d) * 2 * POINTSPERSEGMENT); ellipsis[1] = (Point_3d *) malloc (sizeof (Point_3d) * 2 * POINTSPERSEGMENT); ellipsis[2] = (Point_3d *) malloc (sizeof (Point_3d) * 2 * POINTSPERSEGMENT);// now calculate 1*1 circle for (counter = 0; counter < POINTSPERSEGMENT; counter++) { tempx[counter] = sin (counter * anglestep); tempy[counter] = cos (counter * anglestep); } Point_3d *acuteellipsis = ellipsis[0]; for (counter = 0; counter < POINTSPERSEGMENT; counter++) { acuteellipsis[counter].x = form->Lese_i_j (xindex, xindex) * tempx[counter] + form->Lese_i_j (xindex, yindex) * tempy[counter]; acuteellipsis[counter].y = form->Lese_i_j (yindex, xindex) * tempx[counter] + form->Lese_i_j (yindex, yindex) * tempy[counter]; acuteellipsis[counter].z = form->Lese_i_j (zindex, xindex) * tempx[counter] + form->Lese_i_j (zindex, yindex) * tempy[counter]; acuteellipsis[counter + POINTSPERSEGMENT].x = form->Lese_i_j (xindex, xindex) * tempy[counter] - form->Lese_i_j (xindex, yindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].y = form->Lese_i_j (yindex, xindex) * tempy[counter] - form->Lese_i_j (yindex, yindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].z = form->Lese_i_j (zindex, xindex) * tempy[counter] - form->Lese_i_j (zindex, yindex) * tempx[counter]; } acuteellipsis = ellipsis[1]; for (counter = 0; counter < POINTSPERSEGMENT; counter++) { acuteellipsis[counter].x = form->Lese_i_j (xindex, zindex) * tempx[counter] + form->Lese_i_j (xindex, yindex) * tempy[counter]; acuteellipsis[counter].y = form->Lese_i_j (yindex, zindex) * tempx[counter] + form->Lese_i_j (yindex, yindex) * tempy[counter]; acuteellipsis[counter].z = form->Lese_i_j (zindex, zindex) * tempx[counter] + form->Lese_i_j (zindex, yindex) * tempy[counter]; acuteellipsis[counter + POINTSPERSEGMENT].x = form->Lese_i_j (xindex, zindex) * tempy[counter] - form->Lese_i_j (xindex, yindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].y = form->Lese_i_j (yindex, zindex) * tempy[counter] - form->Lese_i_j (yindex, yindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].z = form->Lese_i_j (zindex, zindex) * tempy[counter] - form->Lese_i_j (zindex, yindex) * tempx[counter]; } acuteellipsis = ellipsis[2]; for (counter = 0; counter < POINTSPERSEGMENT; counter++) { acuteellipsis[counter].x = form->Lese_i_j (xindex, xindex) * tempx[counter] + form->Lese_i_j (xindex, zindex) * tempy[counter]; acuteellipsis[counter].y = form->Lese_i_j (yindex, xindex) * tempx[counter] + form->Lese_i_j (yindex, zindex) * tempy[counter]; acuteellipsis[counter].z = form->Lese_i_j (zindex, xindex) * tempx[counter] + form->Lese_i_j (zindex, zindex) * tempy[counter]; acuteellipsis[counter + POINTSPERSEGMENT].x = form->Lese_i_j (xindex, xindex) * tempy[counter] - form->Lese_i_j (xindex, zindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].y = form->Lese_i_j (yindex, xindex) * tempy[counter] - form->Lese_i_j (yindex, zindex) * tempx[counter]; acuteellipsis[counter + POINTSPERSEGMENT].z = form->Lese_i_j (zindex, xindex) * tempy[counter] - form->Lese_i_j (zindex, zindex) * tempx[counter]; }}void Ellipsis_3d::DrawMe (Output2d_3d * window, Drawable drawable){ short pointcounter, offset = 2 * POINTSPERSEGMENT; char ellipsescounter; for (ellipsescounter = 0; ellipsescounter < 3; ellipsescounter++) { Point_3d *acuteellipsis = ellipsis[ellipsescounter]; XPoint points[4 * POINTSPERSEGMENT + 1]; for (pointcounter = 0; pointcounter < 2 * POINTSPERSEGMENT; pointcounter++) { double xpos, ypos, zpos; xpos = center[0] + acuteellipsis[pointcounter].x; ypos = center[1] + acuteellipsis[pointcounter].y; zpos = center[2] + acuteellipsis[pointcounter].z; window->WorldtoPixel3d (xpos, ypos, zpos, &(points[pointcounter].x), &(points[pointcounter].y)); xpos = center[0] - acuteellipsis[pointcounter].x; ypos = center[1] - acuteellipsis[pointcounter].y; zpos = center[2] - acuteellipsis[pointcounter].z; window->WorldtoPixel3d (xpos, ypos, zpos, &(points[pointcounter + offset].x), &(points[pointcounter + offset].y)); } points[pointcounter + offset].x = points[0].x; points[pointcounter + offset].y = points[0].y; XDrawLines (window->Getdisplay (), drawable, window->Getgc (), points, 4 * POINTSPERSEGMENT + 1, CoordModeOrigin); }}Ellipsis_3d::~Ellipsis_3d (){ free (ellipsis[0]); free (ellipsis[1]); free (ellipsis[2]);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -