| |||||||
Du magst keine Werbung? Wir auch nicht!
Einfach registrieren und die Werbung ist weg. Diese Nachricht sehen nur nicht registrierte Nutzer.
![]() |
| | LinkBack | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Bugfixer Registriert seit: Nov 2001 Ort: #
Beiträge: 572
|
hallihallo Ich hab die letzte woche damit verbracht den sh algorytmus in flash mx zu implementieren. Ein beispiel in flash hätte mir dabei sehr geholfen, sowas gibts aber glaube ich noch nicht. Deswegen stell ich jetzt hier her ![]() Das ganze ist zwar für flash zu viel, überhaupt wegen der drawing api und so, naja vielleicht kanns trozdem mal wer brauchen. greez |
| | |
| | #2 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
Sehr schön secp, ich habe dein Script gleich mal um ein Draggen des Dreiecks erweitert, damit man noch besser sieht, um was es geht. ActionScript:
btw. im neuen Powerflasherbuch gibt es auch einen Abschnitt darüber. mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting Geändert von bokel (09-08-2002 um 13:59 Uhr) |
| | |
| | #3 (permalink) |
| Bugfixer Registriert seit: Nov 2001 Ort: #
Beiträge: 572
|
wow und gegen alle kanten. dann würde ich dir meine aufgespeedete variante vorschlagen: Code: array.prototype.clipPolyH = function(wert) {
var sh_pol = new Array();
var np=-1;
this[this.length] = [this[0][0], this[0][1]];
for( var i=1; i<this.length; i++) {
if(this[i-1][1] <= wert) {
sh_pol[++np] = [this[i-1][0], this[i-1][1]];
}
if((this[i-1][1] <= wert) != (this[i][1] <= wert)) {
sh_pol[++np] = [ ((wert-this[i-1][1]) / ((this[i][1] - this[i-1][1]) / (this[i][0] - this[i-1][0]))) + this[i-1][0], wert ];
}
}
return sh_pol;
}
array.prototype.clipPolyX = function(wert) {
var sh_pol = new Array();
var np=-1;
this[this.length] = [this[0][0], this[0][1]];
for( var i=1; i<this.length; i++) {
if(this[i-1][0] >= wert) {
sh_pol[++np] = [this[i-1][0], this[i-1][1]];
}
if(( this[i-1][0] >= wert) != (this[i][0] >= wert)) {
sh_pol[++np] =[wert, ((wert-this[i-1][0]) * ((this[i][1] - this[i-1][1]) / (this[i][0] - this[i-1][0]))) + this[i-1][1]];
}
}
return sh_pol;
}
array.prototype.clipPolyW = function(wert) {
var sh_pol = new Array();
np=-1;
this[this.length] = [this[0][0], this[0][1]];
for( var i=1; i<this.length; i++) {
if(this[i-1][0] <= wert) {
sh_pol[++np] = [this[i-1][0], this[i-1][1]];
}
if((this[i-1][0] <= wert) != (this[i][0] <= wert)) {
sh_pol[++np] = [wert, ((wert-this[i-1][0]) * ((this[i][1] - this[i-1][1]) / (this[i][0] - this[i-1][0]))) + this[i-1][1]];
}
}
return sh_pol;
}
array.prototype.clipPolyY = function(wert) {
var sh_pol = new Array();
np=-1;
this[this.length] = [this[0][0], this[0][1]];
for( var i=1; i<this.length; i++) {
if(this[i-1][1] >= wert) {
sh_pol[++np] = [this[i-1][0], this[i-1][1]];
}
if((this[i-1][1] >= wert) != (this[i][1] >= wert)) {
sh_pol[++np] = [ ((wert-this[i-1][1]) / ((this[i][1] - this[i-1][1]) / (this[i][0] - this[i-1][0]))) + this[i-1][0], wert ];
}
}
return sh_pol;
} |
| | |
| | #5 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
Wenn du was probierst ? Hast du ein Beispiel ? Btw. ich würde auf das zweidimensionale Array verzichten und die x und y werte einfach hintereinander in ein normales Array schreiben. mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting |
| | |
| | #7 (permalink) |
| Bugfixer Registriert seit: Nov 2001 Ort: #
Beiträge: 572
|
ich habs jetzt auc h´auf 1dim umgestellt, jetzt würde ich gerne keine arrays hin und herschieben müssen, das schaff ich aber nicht - vielleciht geht das gar nicht? hier mal ein versuch : ActionScript:
der clipPolyX prototyp funzt wie vorher, nur 1dim. Beim yClip hab ich das probiert, das das array direkt bearb. wird. Ich check da aber irgendwas nicht . Wahrscheinlich muß ich da irgendwas tmp´n. Das ist mir irgendwie zu hoch
|
| | |
| | #8 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
Schau dir mal die Doku von array.splice an, dann klappt es auch Ich glaube aber nicht, dass das was bringt, es wird eher langsamer. push ist übrigens auch schneller als a[a.length]=b, zumindest seit dem neuen 6er Plugin. ActionScript:
Hier ist eine optimierte Version von clipPolyX ActionScript:
mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting Geändert von bokel (10-08-2002 um 12:25 Uhr) |
| | |
| | #9 (permalink) |
| Bugfixer Registriert seit: Nov 2001 Ort: #
Beiträge: 572
|
hmm ,da sind meine array protos mit 2 dimensionen ja genauso schnell. Ich glaub schon das das sh_pol array viel zeit benötigt, das wird ja dann by value zurückgegeben, oder? by ref? naja pointer wären cool . Das splice ist nicht das prob, sondern der algo. |
| | |
| | #10 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
Wie hast du denn gemessen ? Ich bekomme die folgenden Ergebnisse: 3286 clipPolyX eindimensional bokel 3977 Array.clipPolyX eindimensional secp 4445 Array.clipPolyX zweidimensional secp ActionScript:
Arrays werden by reference übergeben. mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting Geändert von bokel (10-08-2002 um 13:06 Uhr) |
| | |
| | #12 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
ja, genau die habe ich benutzt mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting |
| | |
| | #14 (permalink) |
| Bugfixer Registriert seit: Nov 2001 Ort: #
Beiträge: 572
|
hmm. ich hab das jetzt mal getestet. dabei ist mir wiedermal aufgefallen das das testen nichts bringt! hier mein test ergebnis: Code: //Polygon zeichen funktion, übernimmt ein geschlossenes Polygon
function draw(pol, color, alpha) {
lineStyle(0,color,alpha);
beginFill(color,alpha);
moveTo(pol[0], pol[1]);
for(i=2; i<pol.length;i+=2) {
lineTo(pol[i], pol[i+1]);
}
endFill();
}
array.prototype.clipPolyX1Dim = function(wert) {
var sh_pol = new Array();
var np=-1;
this.push(this[0]);
this.push(this[1]);
for( var i=2; i<this.length; i+=2) {
if(this[i-2] >= wert) {
sh_pol[++np]=this[i-2];
sh_pol[++np]=this[i-1];
}
if(( this[i-2] >= wert) != (this[i] >= wert) ) {
sh_pol[++np] = wert;
sh_pol[++np] = ((wert-this[i-2]) * ((this[i+1] - this[i-1]) / (this[i] - this[i-2]))) + this[i-1];
}
}
return sh_pol;
}
//bokels
//gibt ein neues, geclipptes poly zurück.
function clipPolyX_bokel(poly, wert) {
var sh_pol = new Array();
var x1, y1, x2, y2;
var a, j;
poly.push(x1=poly[0]);
poly.push(y1=poly[1]);
j = poly.length-2;
a = (x1 >= wert);
while(j > 0){
// koordinaten kommen umgekehrt
y2 = poly[--j];
x2 = poly[--j];
//
if (a) {
sh_pol.push(x1);
sh_pol.push(y1);
}
//
//schnittpunkt berechnen
if(a != (x2 >= wert)){
sh_pol.push(wert);
sh_pol.push((wert - x1) * (y2 - y1) / (x2 - x1) + y1);
a = !a;
}
//
x1 = x2;
y1 = y2;
}
return sh_pol;
}
//Das original polygon
orig_pol = new Array(0,-100,
100,100,
-100,100);
max = 50;
/// erster Aufruf immer schneller !!
t = getTimer();
for(i=0; i< max; i++) newPolmy = orig_pol.clipPolyX1Dim(0);
trace("1Dim : " + (getTimer() - t));
//zweiter immer langsamer!!
t = getTimer();
for(i=0; i< max; i++) newPol_bokel= clipPolyX_bokel(orig_pol, 0);
trace("bokels: " + (getTimer() - t)); 1Dim : 271 bokels: 599 Allerdings wenn ich als erstes deine func ausführe ist deine schneller, und meine 3mal so langsan. Was soll das? |
| | |
| | #15 (permalink) |
| helpQLODhelp Registriert seit: Feb 2002 Ort: Köln
Beiträge: 8.505
|
Möglicherweise liegt es daran, dass das originale Array immer laenger wird, und meine Methode dann sozusagen unter erschwerten Bedingungen ablaeuft. Versuch es mal so: (das Array wird jedesmal neu kopiert.) ActionScript:
mfg r.
__________________ Ralf Bokelberg™ - Flex & Flash Consulting Geändert von bokel (11-08-2002 um 10:35 Uhr) |
| | |
![]() |
| Lesezeichen |
| Themen-Optionen | |
| Ansicht | |
| |