You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('') and can be up to 35 characters long.
49 lines
2.0 KiB
49 lines
2.0 KiB
(load "displaylib.scm")


(title "Exercise 2.48")


(doc "A directed line segment in the plane can be represented as a pair of vectors  the vector running from the origin to the startpoint of the segment, and the vector running from the origin to the endpoint of the segment. Use your vector representation from exercise 2.46 to define a representation for segments with a constructor makesegment and selectors startsegment and endsegment.")




;  Vectors 2.46 


(define (makevect x y) (list x y))


(define (xcorvect v) (car v))


(define (ycorvect v) (cadr v))


(define (addvect v w) (makevect


(+ (xcorvect v) (xcorvect w))


(+ (ycorvect v) (ycorvect w))))


(define (subvect v w) (makevect


( (xcorvect v) (xcorvect w))


( (ycorvect v) (ycorvect w))))


(define (scalevect s v) (makevect


(* s (xcorvect v))


(* s (ycorvect v))))




(define origin (makevect 0 0))


(define oneone (makevect 1 1))


(define xunit (makevect 1 0))


(define yunit (makevect 0 1))


(define halfhalf (makevect 0.5 0.5))




;  Frames 2.47 


;  frame with list representation 


(define (makeframe origin edge1 edge2)


(list origin edge1 edge2))


(define (originframe f) (car f))


(define (edge1frame f) (cadr f))


(define (edge2frame f) (caddr f))


;  frame with cons representation 


(define (makeframecons origin edge1 edge2)(cons origin (cons edge1 edge2)))


(define (originframecons f) (car f))


(define (edge1framecons f) (car (cdr f)))


(define (edge2framecons f) (cdr (cdr f)))


; 


; START


; 




(define (makesegment start end) (list start end))


(define (startsegment s) (car s))


(define (endsegment s) (cadr s))




(print "START")


(define segment (makesegment halfhalf oneone))


(display segment)(newline)


(display (startsegment segment))(newline)


(display (endsegment segment))(newline)


