1

別のスタック オーバーフロー ポストからベクトル ポストローテーションのバウンディング ボックスの幅と高さを計算する最良の方法を見つけました。これはうまくいきました。私の問題は、回転したベクトルの境界ボックスの新しい x、y 座標を計算することです。これが私のjavascriptです。newWidth, newHeight変数は正しいです -rotatedXPos, rotatedYPosただし、変数は正しくありません。これx0, y0は、ベクトルの回転する中央である必要があると思いますが、間違っているためです (上部の x、y 座標のみに設定されています)。ベクトルの右/左、私は間違っていることを知っています)。

this.options.rotationAngle = parseInt(this.options.lastRotationAngle);
var degreesAsRadians = this.options.rotationAngle*Math.PI/180;
var points = new Array();
points.push({x:0, y:0});
points.push({x:this.options.width, y:0});
points.push({x:0, y:this.options.height});
points.push({x:this.options.width, y:this.options.height});
var bb = new Array();
bb['left'] = 0; bb['right'] = 0; bb['top'] = 0; bb['bottom'] = 0;

$A(points).each(function(p) {
  var newX = Math.abs(parseInt(p.x * Math.cos(degreesAsRadians) + p.y *  Math.sin(degreesAsRadians)));
  var newY = Math.abs(parseInt(p.x * Math.sin(degreesAsRadians) + p.y * Math.cos(degreesAsRadians)));
  bb['left'] = Math.min(bb['left'], newX);
  bb['right'] = Math.max(bb['right'], newX);
  bb['top'] = Math.min(bb['top'], newY);
  bb['bottom'] = Math.max(bb['bottom'], newY); 
});

var newWidth = parseInt(Math.abs(bb['right'] - bb['left']));
var newHeight = parseInt(Math.abs(bb['bottom'] - bb['top']));

Object.extend(this.options, {
rotatedWidth: newWidth
,rotatedHeight: newHeight 
});

var x0 = this.options.xPos;
var y0 = this.options.yPos;

this.options.rotatedXPos = x0+(this.options.xPos-x0)*Math.cos(degreesAsRadians)+(this.options.yPos-y0)*Math.sin(degreesAsRadians);
this.options.rotatedYPos = y0-(this.options.xPos-x0)*Math.sin(degreesAsRadians)+(this.options.yPos-y0)*Math.cos(degreesAsRadians);

そして、これがビデオです。ビデオでは、赤いボックスは newWidth、newHeight を正しく示していますが、新しく回転したベクトルの上部/左側で と が計算されていませんrotatedXPosrotatedYPos助けていただければ幸いです。どうもありがとうございました。

4

1 に答える 1

1

楕円の中心が (xc, yc) であることがわかっている場合、境界ボックスの左上隅は

(xc - 新しい幅/2、yc - 新しい高さ/2)

(+x が正しく、+y が下がると仮定します)。

于 2009-12-19T18:20:20.327 に答える