vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Weird geometry error when using transform matrices and line/polyline #53

Open kchanqvq opened 2 years ago

kchanqvq commented 2 years ago

Test program:

(defsketch test
    ((title "test") (width 640) (height 640))
  (let ((size 48))
    (scale (/ size 2))
    (translate 4 4)
    (with-pen (make-pen :stroke +white+ :weight (/ 2 size))
      #+nil (line 0.4 0.4 1 1)
      #+nil (line 1 1 0.4 0.4)
      (polyline 0.8 0.8 -1 -1 -0.8 -0.8))))

Problem:

  1. the output from the polyline is wrong, it flies outside the screen.

    Screen Shot 2022-08-22 at 3 57 56 PM
  2. The output of the two (commented out in the snippet) line has different position. When composing larger algorithms I find geometry gets put in wrong positions everywhere.

kchanqvq commented 2 years ago

Some more issues:

  1. Turns out polyline breaks completely when I use (with-pen (make-pen :stroke +black+ :weight 2) ...), even without any transform.
  2. The thickness calculation when using line and (with-pen (make-pen :stroke +black+ :weight 2) ...) looks fishy. I see visually inconsistent thickness when there are overlapping lines, could be the triangulation introduced some tiny offset so lines don't overlap exactly.

Update: according to my partial understanding the issue comes from the treatment of collinear or overlapping line segment, which causes intersect-lines to return abnormal values. Not sure about how to solve it...

Kevinpgalligan commented 7 months ago

Relevant article shared by @Gleefre: https://mattdesl.svbtle.com/drawing-lines-is-hard