我有一個繪圖庫,我正在構建source,並且想繪製斜線。我有一個功能(draw-seg-list device color lst)
lst
arg是一個列表,其中包含一行(x0 y0 x1 y1)
的開始線和停止線的列表。我想創建一個函數(make-slope-seg x y m),然後返回以(x,y)爲中心的斜率爲m的線段的點列表。製作一個函數,使線段座標以點(x y)爲中心,斜率爲m
實施例:(make-slope-seg 0 0 0)
- >(-.05 0 .05 0)
和(make-slope-seg .1 .1 1)
- >(.05 .05 .15 .15)
非工作功能我是:
(define (make-slope-cords x y m)
(list (- x .05)
(* y m -1)
(+ x .05)
(* y m)))
它返回不正確的線。如果我使用:
;makes graphics window
(define window (make-graphics-device 'win32))
;plots blue line for function y = x^2 with black axis
(make-plot window 'simple-plot (list "white" "black" "blue" (list (range -1 1 .01) square)))
;makes list of lists containing the slope and x y cords that the slope lines
;are supposed to be centered at
(define cords (map (lambda (s x y)
(list s x y))
(map (lambda (x) (* 2 x)) (range -1 1 .1))
(range -1 1 .1)
(map square (range -1 1 .1))))
;plots the line segments generated by mapping make-slope-cords to the coordinate list
(draw-seg-list window "red"
(map (lambda (lst)
(make-slope-cords (car lst) (cadr lst) (caddr lst)))
cords))
但是我它與斜率爲斜率要寬度0.1(1平方上的圖像中的網格)輸出紅線沿着x軸以.1間隔的每個點處的藍線(lambda(x)(square x))。
備註:假定draw-seg-list
有效。我只需要幫助,使功能make-slope-cords
產生一個正確的配對名單