首先,你的集合符号很奇怪.你的意思是S =( - ∞,-2)∪(-1,∞),即S是两个开放区间的并集.您还可以写S = [ - 2,-1] ^ C或S = {x∈ℝ:x <-2或x> -1}.此外,你的照片肯定不是抛物线; 它看起来更像是一个双曲线.
无论如何,绘制函数f:ℝ→ graphs的图表很简单.您只需要处理逻辑坐标系和屏幕坐标系之间的坐标转换.限定
type
TRealVector = record
X, Y: real;
end;
Run Code Online (Sandbox Code Playgroud)
作为ℝ²中的一个点,你的地图是
const
xmin = -10;
xmax = 10;
ymin = -10;
ymax = 10;
function TForm5.LogToScreen(LogPoint: TRealVector): TPoint;
begin
result.X := round(ClientWidth * (LogPoint.X - xmin) / (xmax - xmin));
result.Y := ClientHeight - round(ClientHeight * (LogPoint.Y - ymin) / (ymax - ymin));
end;
function TForm5.ScreenToLog(ScreenPoint: TPoint): TRealVector;
begin
result.X := xmin + (ScreenPoint.X / ClientWidth) * (xmax - xmin);
result.Y := ymin + (ymax - ymin) * (ClientHeight - ScreenPoint.Y) / ClientHeight;
end;
Run Code Online (Sandbox Code Playgroud)
然后你只需要策划!
procedure TForm5.FormPaint(Sender: TObject);
var
PrevPoint, CurrPoint: TPoint;
x: integer;
logx: real;
logy: real;
y: integer;
begin
PrevPoint := Point(-1, -1);
Canvas.Brush.Color := clWhite;
Canvas.FillRect(ClientRect);
for x := 0 to ClientWidth - 1 do
begin
logx := ScreenToLog(Point(x, 0)).X;
logy := logx*logx; // y = f(x)
y := LogToScreen(RealVector(logx, logy)).Y;
CurrPoint := Point(x, y);
if PrevPoint.X = -1 then
Canvas.MoveTo(CurrPoint.X, CurrPoint.Y)
else
Canvas.LineTo(CurrPoint.X, CurrPoint.Y);
PrevPoint := CurrPoint;
end;
end;
Run Code Online (Sandbox Code Playgroud)
别忘了:
procedure TForm5.FormResize(Sender: TObject);
begin
Invalidate;
end;
Run Code Online (Sandbox Code Playgroud)
截图http://privat.rejbrand.se/dparabolaplot.png