Does anyone know how to calculate the coordinates of the rectangle/square box on the surface of the circle?
I can get the center of the rectangle and draw a line through it but trying to get the coordinates.
var lineHeight = 25;
var baseX = circle.x + circleRadius/2 * Math.cos(angleRadians);
var baseY = circle.y + circleRadius/2 * Math.sin(angleRadians);
var x1 = baseX + lineHeight*Math.cos(angleRadians);
var y1 = baseY + lineHeight*Math.sin(angleRadians);
this.testgraphics = this.add.graphics();
this.testgraphics.lineStyle(4, 0xff0000);
this.testgraphics.beginPath();
this.testgraphics.moveTo(baseX, baseY);
this.testgraphics.lineTo(x1, y1);
this.testgraphics.closePath();
this.testgraphics.strokePath();
Why do you use a half of circleRadius ( circleRadius/2
)?
baseX = circleCenterX + circleRadius * cos(angleRadians)
baseY = circleCenterY + circleRadius * sin(angleRadians)
corner coordinates
x1 = baseX - rectWidth / 2 * sin(angleRadians) //note sign
y1 = baseY + rectWidth / 2 * cos(angleRadians)
x2 = baseX - rectWidth / 2 * sin(angleRadians) + rectHeight * cos(angleRadians)
y2 = baseY + rectWidth / 2 * cos(angleRadians) + rectHeight * sin(angleRadians)
x3 = baseX + rectWidth / 2 * sin(angleRadians) + rectHeight * cos(angleRadians)
y3 = baseY - rectWidth / 2 * cos(angleRadians) + rectHeight * sin(angleRadians)
x4 = baseX + rectWidth / 2 * sin(angleRadians)
y4 = baseY - rectWidth / 2 * cos(angleRadians)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.