geometry

geometry - ; The first three lines of this file were...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname geometry) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; Ru Wang 20319247 CS135 001 Tut 108 ; ;; Question 3: ; ;; Part a: ;; Data Definition: (define-struct line (point slope)) ;; Analysis: Functions that come along with the structure: ;; constructor: make-line: consumes a posn and a number or 'vertical symbol to make a line ;; selector: line-point: returns the point for the line in posn. ;; posn-x and posn-y also come as well with the structure posn. ;; selector: line-slope: returns a slope in number or the symbol 'vertical when slope is vertical (infinite) s ;; part b: ;; points->line: posn posn -> line ;; purpose: to consume 2 points and generate a line out of them ;; Template: ;; (define (points->line point1 point2) ;; ...(x-posn point1). .. ;; ...(y-posn point1). .. ;; ...(x-posn point2). .. ;; ...(y-posn point2). ..) ;; Examples: (points->line (make-posn 1 1) (make-posn 1 1)) => error: 2 points given are the same ;; (points->line (make-posn 1 1) (make-posn 2 2)) => (make-line (make- posn 1 1) 1) ;; (points->line (make-posn 1 1) (make-posn -1 2)) => (make-line (make- posn 1 1) -0.5) ;; (points->line (make-posn 1 1) (make-posn 1 2)) => (make-line (make- posn 1 1) 'vertical) ;;Definition: (define (points->line posn1 posn2) (make-line posn1 (cond [(and (equal? (posn-x posn1) (posn-x posn2))(not(equal? posn1 posn2))) 'vertical] [else (/ (- (posn-y posn1) (posn-y posn2)) (- (posn-x posn1) (posn-x posn2)))]))) ;;Tests: (check-expect(points->line (make-posn 1 1) (make-posn 2 2)) (make-line (make-posn 1 1) 1)) (check-expect(points->line (make-posn 1 1) (make-posn -1 2)) (make-line (make-posn 1 1) -0.5))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

geometry - ; The first three lines of this file were...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online