Make a function that makes line segment coordinates centered at point (x y) with slope m

Anandamide

I have a plotting library I'm building source, and want to plot slope lines. I have a function (draw-seg-list device color lst) with the lst arg being a list containing lists with the start and stop cords of a line (x0 y0 x1 y1). I want to make a function (make-slope-seg x y m) that then returns the point list for a line segment centered at (x, y) with slope m.

Example: (make-slope-seg 0 0 0) -> (-.05 0 .05 0) and (make-slope-seg .1 .1 1) -> (.05 .05 .15 .15)

The non-working function I have is:

(define (make-slope-cords x y m)
  (list (- x .05)
        (* y m -1)
        (+ x .05)
        (* y m)))

Which returns the incorrect lines. If I use :

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

It outputs the following: enter image description here

But I want it to output red lines of width .1 (1 square on the grid in the image) with slope being the slope of the blue line(lambda (x) (square x)) at each point spaced by .1 along the x axis.

NOTE: assume that draw-seg-list works. I just need assistance in making the function make-slope-cords produce a the correct list of cordinates

Anandamide

Well experimenting around I was able to determine the answer.

(define (make-sloped-seg x y m)
  (define b (- y (* m x)))
  (list (- x .03)
        (+ (* m (- x .03)) b)
        (+ x .03)
        (+ (* m (+ x .03)) b)))

It determines the y-intercept (b) at the beginning of the calculation, and then generates the points using the correct intercept

example:

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

outputs the following: enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I find the slope (m) for a line given a point (x,y) on the line and the line's angle from the y axis in python?

From Dev

Finding the coordinates on the image knowing the center point and slope of a line

From Dev

How to find position of point that is x unit distant from AB line segment and y unit distant from BC line segment?

From Dev

Finding x,y coordinates of a point on an Archimedean spiral

From Dev

Find out the coordinates using slope and start point

From Dev

determinate: is point on line segment

From Dev

How to get X Y coordinates in resizable function?

From Dev

Finding coordinates of a point on a line

From Dev

Is it somehow possible to check if points `x` and `y` is in a line when only the y-intercept and the slope is given?

From Dev

Sorting coordinates of point cloud in accordance with X, Y or Z value

From Dev

Convert (x, y) pixel coordinates in google.maps.Point

From Dev

Converting text document coordinates 'x, y' to float point list object

From Dev

Calculating integrer x and y coordinates around point by range variable

From Dev

Find the nearest point to (x,y) coordinates on mesh (MATLAB)

From Dev

Converting text document coordinates 'x, y' to float point list object

From Dev

How to Drawing a curve line(peaks) using list of x,y coordinates

From Dev

Find x,y coordinates of line (from binary image) in Matlab

From Dev

Snap SVG change line x,y coordinates using JavaScript

From Dev

sampling x, y coordinates from an equation of a line or curve

From Dev

Drawing curve line peaks using list of x,y coordinates points

From Dev

Plot segment between point and line

From Dev

Plotting a line in a chart given the y intercept and slope

From Dev

get coordinates of arrow of a line point

From Dev

Show X and Y coordinates?

From Dev

jasmine test for function that sets x, y click coordinates to textboxes

From Dev

Calculate Projected Point location (x,y) on given line start(x,y) end(x,y)

From Dev

createjs, animating a line with x1,y1 and x2,y2 coordinates

From Dev

How to plot a line with slope and one point given? Python

From Dev

Does x=y makes x pointer to y?

Related Related

  1. 1

    How do I find the slope (m) for a line given a point (x,y) on the line and the line's angle from the y axis in python?

  2. 2

    Finding the coordinates on the image knowing the center point and slope of a line

  3. 3

    How to find position of point that is x unit distant from AB line segment and y unit distant from BC line segment?

  4. 4

    Finding x,y coordinates of a point on an Archimedean spiral

  5. 5

    Find out the coordinates using slope and start point

  6. 6

    determinate: is point on line segment

  7. 7

    How to get X Y coordinates in resizable function?

  8. 8

    Finding coordinates of a point on a line

  9. 9

    Is it somehow possible to check if points `x` and `y` is in a line when only the y-intercept and the slope is given?

  10. 10

    Sorting coordinates of point cloud in accordance with X, Y or Z value

  11. 11

    Convert (x, y) pixel coordinates in google.maps.Point

  12. 12

    Converting text document coordinates 'x, y' to float point list object

  13. 13

    Calculating integrer x and y coordinates around point by range variable

  14. 14

    Find the nearest point to (x,y) coordinates on mesh (MATLAB)

  15. 15

    Converting text document coordinates 'x, y' to float point list object

  16. 16

    How to Drawing a curve line(peaks) using list of x,y coordinates

  17. 17

    Find x,y coordinates of line (from binary image) in Matlab

  18. 18

    Snap SVG change line x,y coordinates using JavaScript

  19. 19

    sampling x, y coordinates from an equation of a line or curve

  20. 20

    Drawing curve line peaks using list of x,y coordinates points

  21. 21

    Plot segment between point and line

  22. 22

    Plotting a line in a chart given the y intercept and slope

  23. 23

    get coordinates of arrow of a line point

  24. 24

    Show X and Y coordinates?

  25. 25

    jasmine test for function that sets x, y click coordinates to textboxes

  26. 26

    Calculate Projected Point location (x,y) on given line start(x,y) end(x,y)

  27. 27

    createjs, animating a line with x1,y1 and x2,y2 coordinates

  28. 28

    How to plot a line with slope and one point given? Python

  29. 29

    Does x=y makes x pointer to y?

HotTag

Archive