program Pyramid; uses Graph; const rPyr = 50; {Радиус основания пирамиды} hPyr = 200; {Высота пирамиды} A = 0; B = 0; C = 1; D = 150; type tPoint = record {Точка} x, y, z: real end; tLine = record {Прямая} bol, eol: tPoint end; tPlane = record {Плоскость} A, B, C, D: real end; tVector = record {Вектор} x, y, z: real end; var Gd, Gm : Integer; {Графика} Radius : Integer; {Радиус} p1, p2 : tPoint; {Точки} pInt : tPoint; {Точка пересечения} pBuf : tPoint; angle : real; lin : tLine; plane : tPlane; procedure Interception(l: tLine; s: tPlane); {Пересечение отрезка и} var {плоскости} p : tVector; M, N, t: real; begin p.x:= l.eol.x - l.bol.x; p.y:= l.eol.y - l.bol.y; p.z:= l.eol.z - l.bol.z; M:= s.A*p.x + s.B*p.y + s.C*p.z; N:= s.A*l.bol.x + s.B*l.bol.y + s.C*l.bol.z + s.D; if M <> 0 then begin t:= -N/M; pInt.x:= l.bol.x + p.x*t; pInt.y:= l.bol.y + p.y*t; pInt.z:= l.bol.z + p.z*t; end; end; procedure Proection(var p: tPoint); {Проекция (кабинетная)} const two = 2; var k: real; begin k:= two*sqrt(two); p.x:= p.x + p.y/k; p.y:= p.z + p.y/k; end; procedure DrawAxes(c: integer); {Рисование осей} const indent = 10; begin SetColor(c); Line(GetMaxX div 2, GetMaxY div 2, GetMaxX, GetMaxY div 2); {X} OutTextXY(GetMaxX - indent, GetMaxY div 2 + indent, 'X'); Line(GetMaxX div 2, GetMaxY div 2, 0, GetMaxY); {Y} OutTextXY(0, GetMaxY - 2*indent, 'Y'); Line(GetMaxX div 2, GetMaxY div 2, GetMaxX div 2, 0); {Z} OutTextXY(GetMaxX div 2 +indent, indent, 'Z'); end; procedure DrawPyr(r, h, c: integer); {Рисование пирамиды} var angle: real; {Угол} p : tPoint; {Точка} begin angle:= -pi/3; p.x:= Round(r*Cos(0)); p.y:= Round(r*Sin(0)); p.z:= 0; MoveTo(GetMaxX div 2 + Round(p.x), GetMaxY div 2+ Round(p.y)); while angle <= 2*pi do begin p.x:= Round(r*Cos(angle)); p.y:= Round(r*Sin(angle)); Proection(p); SetColor(c); LineTo(GetMaxX div 2 + Round(p.x), GetMaxY div 2 + Round(p.y)); Line(GetMaxX div 2 + Round(p.x), GetMaxY div 2 + Round(p.y), GetMaxX div 2, GetMaxY div 2 - h ); angle:= angle + pi/3; end; end; begin {Инициализация графики} Gd:= Detect; InitGraph(Gd, Gm, 'C:\BP\BGI'); { Путь к BGI драйверам } if GraphResult <> grOk then Halt; {Рисование} DrawAxes(green); DrawPyr(rPyr, hPyr, white); {Построение линии сечения} lin.eol.x:= 0; lin.eol.y:= 0; lin.eol.z:= hPyr; plane.A:= A; plane.B:= B; plane.C:= C; plane.D:= D; lin.bol.z:= 0; angle:= -pi/3; while angle <= 2*pi do begin lin.bol.x:= Round(rPyr*Cos(angle)); lin.bol.y:= Round(rPyr*Sin(angle)); Interception(lin, plane); Proection(pInt); SetColor(blue); LineTo(GetMaxX div 2 + Round(pInt.x), GetMaxY div 2 + Round(pInt.y)); angle:= angle + pi/3; end; ReadLn; CloseGraph; end.