2016-11-18 6 views
1

Ich versuche, eine 3D-Grafik mit Racket und Dr. Racket zu plotten.Plot 3D-Grafik in Racket

Ich bin mit der Bibliothek plot und ich habe in vielen Grafiken, wie erfolgreich:

#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)) 

aber wenn ich versuche, das klassische Beispiel einer Linie in 2D „y = x“ grafisch darstellen, aber in 3D:

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

Das Programm wird zu einem unendlichen Skript.

Vielleicht ist meine Mathematik falsch.

Die Zeile y = x in 2D wäre f (x, y) = x - y in 3D?

Ich möchte y = x in 3D sehen, das ist was ich will. Wie kann ich das lösen?

+3

Ihr Programm läuft gut für mich, aber Ihre Grundstücksgrenzen sind alle "10", also gibt es nichts zu rendern. Wenn ich sie zu "0 10 0 10" ändere, sehe ich die Ebene "z = x - y". –

Antwort

0

Hier ist ein Beispiel dafür, wie Linien zeichnen:

#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)) 

Wenn Sie die Lösung der Gleichung zeichnen wollen y=z (die eine Ebene ist) Sie können dies tun:

(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)