Cohen’s clipping algorithms

Okay this was homework. I searched for a really long time for a javascript implementation of cohen’s clipping algorithms and could find none. Professor said write it in c but its hard to program mouse clicks in c. With javascript, all it takes is a browser.

1. Cohen-sutherland line clipping algorithm in javascript

2. Sutherland-Hodgman polygon clipping algorithm in javascript.

cohen-hogman polygon clipping in action
cohen-hogman polygon clipping in action

I believe the code is pretty readable – I had commented lavishly. Save them as html files, open in a browser, and keep clicking left mouse button.

And yes, the implementation is not perfect. I basically drew over the edges in white to “erase” it and that is why you see a very thin line outside the rectangle in the image.

One thought on “Cohen’s clipping algorithms

  1. Kevin,
    I found your name in researching Diaspora. I am an individual investor in “special circumstance” transactions (turnarounds, complex project financing, and corporate developments). I am looking to establish a relationship with a student(s) with your interest to work with me on the final stage of a peer to peer financing venture that is very unique, and in which I have several years of time and several hundred thousand invested. Coincidentally, it will also involve the refinement of several algorithms which correlat local markets to small business valuation. However, the innovation lies in securities compliance and on going financial analysis. We are effectively creating a micro junk bond market. It is my belief that there is an application for Diaspora which would be quite meaningful, and there is an opportunity for stock options for the right crew.

    If this is of interest, please email me at Sam@relentlesscapital.co (note that it is “co” not “com”) If so, it would require that we talk by phone. If we both waned to pursue the matter further, it would require that you and your associate(s) sign a Confidentiality/NDA agreement. Following that, I would forward a detailed project description and related planning documents. If discussions continued, I would visit with you and your associate.

    This weekend is actually a good time for me, I am available this weekend and working in my office all day today and tomorrow at 1000 Shore Road in Cape Elizabeth, Maine. I am sure I would enjoy the opportunity to visit with you.

    Note that I have provided the website Mayberrycapital.net; this is a secure beta site. The Home page will only provide starting point data as it is soon to be upgraded for a pilot. I can provide open access after we talk.

    Regards,
    Sam

Leave a comment