0

Title sounds a little confusing but essentially, I have to recreate Sol Lewitt's wall drawing 340 (https://massmoca.org/event/walldrawing340/). Which consists of horizontal lines with voided shapes in the center, a circle, a square, a rectangle, a triangle, a trapezoid, and a parallelogram

I see that I'd need to use an iteration of some kind but I cannot for the life of me think of how I would calculate the individual start / end points of the horizontal lines within the iteration, and then the start / end points of the six voided shapes made from vertical lines.

An explanation that might point me on the right track would be fantastic as I want to learn this for myself. I must complete this using maths for the start / endpoints.

KodyJH
  • 115
  • 6
  • Did somebody assign this as homework recently? Because there have been a spate of these questions. https://stackoverflow.com/questions/68855168/how-to-draw-regular-geometrical-shapes-with-a-series-of-horizontal-or-vertical-l https://stackoverflow.com/questions/57546467/is-it-possible-to-make-canvas-with-background-with-lines-or-canvas-that-isnt-a – Paul Wheeler Sep 01 '21 at 00:15
  • It's for an assignment, I've seen the other posts but no solution has worked for me just yet. – KodyJH Sep 01 '21 at 00:58

1 Answers1

1

This is the same problem as polygon rasterization – you have a shape defined by a series of line segments, and you need to find the points where a ray enters and leaves the polygon.

(For the circle, you could either approximate it as a polygon or write a special-case algorithm, which would be relatively simple)

You can find a lot of google results for polygon rasterization; most of the detail in those references will deal with clipping, which is something you don’t have to worry about.

Since you know that all of your rays start and end outside the polygon, the rough approach would be:

- for each horizontal ray:
  - set x-min = x-max = 0
  - for each polygon segment:
    - find the intersection x of the ray and the line
    - if the intersection is between the segment’s start and end points:
      - if x is less than x-min, set x-min=x
      - if x is greater than x-max, set x-max=x
  - if x-min > 0:
    - draw a line from 0 to x-min, and from x-max to [screen width]

The process for drawing the vertical lines in the interior of the shape is very similar, except the outer loop would iterate over vertical rays, and you’d draw lines from y-min to y-max.

For the line intersection calculations, you may find it helpful to google “parametric representation of line segments”.

bobtato
  • 1,157
  • 1
  • 9
  • 11