在Racket中绘制3D图形

时间:2016-11-18 18:33:15

标签: plot lisp racket

我正在尝试使用Racket和Dr. Racket绘制3D图形。

我正在使用图书馆plot,我在许多图表中取得了成功,例如:

#lang racket

(require plot)

(plot3d (surface3d (lambda (x y) (* x y (+ 1 (- x) (- y)))) (- 2) 2 (- 2) 2))

(plot3d (surface3d (lambda (x y) (* (sin y) x)) (- 1) 1 (- 5) 5))

(plot3d (surface3d (lambda (x y) (+ 4 (expt x 3) (expt y 3) (* -3 x y))) (- 2) 2 (- 2) 2))

但是,当我尝试在2D" y = x"中绘制线条的经典示例时但在3D中:

(plot3d (surface3d (lambda (x y) (+ x (- y)))
         10 10 10 10))

程序变成了无限的脚本。

也许我的数学错了。

2D中的线y = x在3D中是f(x,y)= x - y吗?

我想在3D中看到y = x,这就是我想要的。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

以下是如何绘制线条的示例:

#lang racket
(require plot)

(define (line-through p q)
  (match* (p q)
    [((list px py pz) (list qx qy qz))
     (λ (t)
       (vector (+ px (* t (- qx px)))
               (+ py (* t (- qy py)))
               (+ pz (* t (- qz pz)))))]))

(plot3d (parametric3d (line-through '(1 1 1) '(1 2 3))
                      -1e6 1e6))

如果要将解集设置为等式y=z(这是一个平面) 你可以这样做:

(plot3d (list (surface3d (λ (x y) (- x y))))
        #:x-min -10 #:x-max 10
        #:y-min -10 #:y-max 10
        #:z-min -10 #:z-max 10)
相关问题