1

I'm trying to make use of the following algorithm: http://www.skytopia.com/project/articles/compsci/clipping.html

But for my special case, I don't have a line that crosses the rectangle 2 times, but it starts in the center of the rectangle and only crosses it one single time.

Using the algorithm above I want to get the single intersection point for drawings on a canvas.

Problem: a canvas does not have a normal coordinate space where Y grows to the top, but Y grows to the bottom.

What would I have to change in order to "mirror" the y-axis and make it work in a canvas coordinate system?

Cœur
  • 37,241
  • 25
  • 195
  • 267
membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1
    The way you draw the canvas does not change any of the math. – flup Mar 24 '13 at 20:42
  • Simply "translating" the y-Axis to the cartesian coordinate system can be done thourgh: `cartesianY = canvas.height - y;` - but I think what you need is something like this: http://www.kevlindev.com/gui/math/intersection/index.htm#Anchor-intersectLineLin-49677 – olsn Mar 24 '13 at 22:25

1 Answers1

0

Indeed the algorithm can be just ported as it is for using with canvas. I had some typo in the algor and after elemination it just works as expected.

membersound
  • 81,582
  • 193
  • 585
  • 1,120