...

View Full Version : Polygon Clipping



ez4ne12c
04-30-2004, 05:55 AM
Does anyone know of a javascript polygon clipping routine
I have two simple polygons A and B and i need to be able to
clip A with B
I have found some c programs to do this but i was wondering if any1 has seen a javascript to do this?

Thanks in advance
ez

kwhubby
05-28-2004, 06:47 AM
If I understand what you are trying to do correctly (as in the demonstration here: http://www.cs.man.ac.uk/aig/staff/alan/software/gpc.html) this would only be possible in Java not JavaScript. JavaScript cannot deal with painting and so would be impossible. If What you are trying to do is very simple, it might be possible in JavaScript using divs and images. A request for code like this would be appropriate in the computer programming section.
ps. yes this thread is over a month old, but I hate seeing threads with 0 replies.

Kor
05-28-2004, 09:29 AM
You may "mime" cropping and clipping using layers, but first you must be able to draw a polygon... To do that, see:
http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm

JPM
05-28-2004, 04:37 PM
^ Nice!!!

kwhubby
05-29-2004, 10:04 AM
Wow that jsgraphics thing is impressive Kor. Even though that's an amazingly efficient way of doing this with DHTML it still is limited to relatively simple shapes and still probably a hundred times slower then if you were to use Java. If you wanted to use complex or large polygons this would not be appropriate. Anyways, I have some uses for that jsgraphics thing thanks for posting that site Kor.

GrimChild
05-30-2004, 03:43 PM
Just Browsing Aroung After Posting A Thread.
I've Gotta Say, Thats Quite Impressive !

Kor
05-31-2004, 08:33 AM
To kwhubby:

DHTML iapplications are not so slow as you may think. For the same types (movement,visibility) it is faster than Flash or Java equivalents. Still, the main disadvateges of javascript graphics are:
1. a non-vectorial curves (which is infact a HTML work space disadvantege)
2. intricate way of rotate objects (or transform them upon other axes than X or Y).

Many users avoid Java, due to the latest security wekness. Thus, probably the best present way for a high graphical site is using DHTML in combination with Flash.

kwhubby
05-31-2004, 09:35 AM
JavaScript might be faster for moving visual html objects or hiding and showing them, and certainly more convenient, easier, and comonly found in browsers then java and flash, but emulation of drawing certainly cannot be faster? Try to generate an image with javascript using divs. Even a relatively small image takes a massive amount of time, ineffective for most uses. The dynamically generated divs would suck up a lot or ram and processing time. Try to do 3d rendering in JavaScript: so slow it would be a complete waste of time to make the script. Even In flash 3d rendering would be slow. Both of these are done with a relatively great speed and efficiency in java (take runescape as an example of 3d rendering with java). If the polygons for what ez4ne12c Is trying to do are simple it will be fast enough and optimal for this environment in javascript. But try to do complex series of polygons (where u get tens of thousands of dynamically generated divs), the processing would take much time compared to java. Hopefully what ez4ne12c is trying to do will be simple enough to be efficient in JavaScript using the dhtml example you posted or something similar.

Kor
05-31-2004, 10:03 AM
yes, you might be right. Except that there is a sort of "thermo-dynamics 3-rd law" apllied on connection speed. Java or Flash have a superior speed on final approach, but there is certain time for initial applet to be loaded, which almost compensates for the total time...

In my oppinion, the reason for using Flash or Java for certain applications stands mostly for the vectorial design possibilities, not for speed which, most of the time, is inferior to DHTML application.

But we did not solve ez4ne12c's problem. I said that a DHTML solution would be intricate so, this particular case, a Flash or, if you want it so much, a Java solution would be probably a better one.

kwhubby
05-31-2004, 10:32 AM
Very true, loading time of the applet/flash code and plugin would be a major issue here, that's why we need more information from ez4ne12c in order to see what this is being used for, and exactly what and how he wants to clip B with A.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum