diff --git a/src/components/Roof2.jsx b/src/components/Roof2.jsx index 00661aca..9d6d0d1d 100644 --- a/src/components/Roof2.jsx +++ b/src/components/Roof2.jsx @@ -577,922 +577,6 @@ export default function Roof2(props) { canvas?.renderAll() } - const createPentagon2 = () => { - const a = 400 //Number(prompt('a')) - const b = 200 //Number(prompt('b')) - const c = 250 //Number(prompt('c')) - const d = 150 //Number(prompt('d')) - - const t = (c * (a - b)) / (200 + c) - - const t2 = Math.sqrt(c * c + t * t) - - const t3 = Math.sqrt((c - d) * (c - d) + (a - b - t) * (a - b - t)) - - const angle = Math.atan(t2 / t) - const angle2 = Math.atan(t3 / (a - b - t)) - - let isDrawing = true - let pentagon - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - - pentagon = new QPolygon( - [ - { x: pointer.x - a / 2, y: pointer.y + a / 2 - d }, - { x: pointer.x + a / 2, y: pointer.y + a / 2 - d }, - { x: pointer.x + a / 2, y: pointer.y + a / 2 - d - d }, - { x: pointer.x + a / 2 - b, y: pointer.y + a / 2 - d - d }, - { - x: pointer.x + a / 2 - b - t3 * Math.cos(angle), - y: pointer.y + a / 2 - d - d - t3 * Math.sin(angle), - }, - /*{ - x: pointer.x - a / 2 + t2 * Math.cos(angle), - y: pointer.y + a / 2 - d - t2 * Math.sin(angle), - },*/ - ], - { - fill: 'transparent', - stroke: 'gray', - strokeWidth: 1, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(pentagon) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - pentagon.set('name', 'roof') - pentagon.set('stroke', 2) - canvas?.renderAll() - }) - } - - const createTemplate10 = () => { - const length1 = Number(prompt('1번')) - const length2 = Number(prompt('2번')) - const length3 = Number(prompt('3번')) - const length4 = Number(prompt('4번')) - const length5 = Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y - (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y + (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 - length5 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 + length5 }, - { - x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, - y: pointer.y + (length4 + length5) / 2 - length5 + length5, - }, - { - x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, - y: pointer.y + (length4 + length5) / 2 - length5 + length5 - (length4 + length5), - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate11 = () => { - const length1 = 200 //Number(prompt('1번')) - const length2 = 100 //Number(prompt('2번')) - const length3 = 400 //Number(prompt('3번')) - const length4 = 300 //Number(prompt('4번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length3 }, - { x: pointer.x - length1 / 2 + length1 - (length1 - length2), y: pointer.y + length4 / 2 - length3 }, - { x: pointer.x - length1 / 2 + length1 - (length1 - length2), y: pointer.y + length4 / 2 - length3 + (length3 - length4) }, - { x: pointer.x - length1 / 2 + length1 - (length1 - length2) - length2, y: pointer.y + length4 / 2 - length3 + (length3 - length4) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate12 = () => { - const length1 = 200 //Number(prompt('1번')) - const length2 = 100 //Number(prompt('2번')) - const length3 = 400 //Number(prompt('3번')) - const length4 = 300 //Number(prompt('4번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length4 - (length3 - length4) }, - { x: pointer.x - length1 / 2 + length1 - length2 - (length1 - length2), y: pointer.y + length4 / 2 - length4 - (length3 - length4) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate13 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 100 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, - { x: pointer.x - length1 / 2 + length1 - length3 - length2, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate14 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 100 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x + length1 / 2 - length1 + length3, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x + length1 / 2 - length1 + length3, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, - { x: pointer.x + length1 / 2 - length1 + length3 + length2, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate15 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 100 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - { x: pointer.x + length1 / 2 - length1 + length2 + length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate16 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 100 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - { x: pointer.x - length1 / 2 + length1 - length2 - length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate17 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 250 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - { x: pointer.x - length1 / 2 + length1 - length2 - length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate18 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 150 //Number(prompt('2번')) - const length3 = 250 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 200 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, - { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 }, - { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - { x: pointer.x + length1 / 2 - length1 + length2 + length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate19 = () => { - const length1 = 500 //Number(prompt('1번')) - const length2 = 300 //Number(prompt('2번')) - const length3 = 400 //Number(prompt('3번')) - const length4 = 300 //Number(prompt('4번')) - - // 좌측 빗변 - const leftHypotenuse = Math.sqrt(((length1 - length2) / 2) ** 2 + length3 ** 2) - const rightHypotenuse = (length4 / length3) * leftHypotenuse - - const leftAngle = Math.acos((length1 - length2) / 2 / leftHypotenuse) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(leftAngle), y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(leftAngle) }, - { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(leftAngle), y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(leftAngle) }, - { - x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(leftAngle) - length2, - y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(leftAngle), - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate20 = () => { - const length1 = 500 //Number(prompt('1번')) - const length2 = 300 //Number(prompt('2번')) - const length3 = 400 //Number(prompt('3번')) - const length4 = 300 //Number(prompt('4번')) - - // 좌측 빗변 - const rightHypotenuse = Math.sqrt(((length1 - length2) / 2) ** 2 + length3 ** 2) - const leftHypotenuse = (length4 / length3) * rightHypotenuse - - const rightAngle = Math.acos((length1 - length2) / 2 / rightHypotenuse) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { - x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(rightAngle), - y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(rightAngle), - }, - { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(rightAngle), y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(rightAngle) }, - { - x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(rightAngle) + length2, - y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(rightAngle), - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - /** - * 19~22번은 못함 - */ - const createTemplate23 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 100 //Number(prompt('2번')) - const length3 = 150 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('4번')) - const length5 = 300 //Number(prompt('5번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2 + length2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, - { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 + length4 }, - { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 + length4 }, - { x: pointer.x - length1 / 2 + length2 + (length1 - length2 - length3) / 2, y: pointer.y + length4 / 2 - length4 + length5 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - - const createTemplate24 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 400 //Number(prompt('2번')) - const length3 = 300 //Number(prompt('3번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length2 - length2 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 }, - { x: pointer.x, y: pointer.y + length2 - length2 / 2 - length3 - (length2 - length3) }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 + length3 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate25 = () => { - const length1 = 300 //Number(prompt('1번')) - const length2 = 200 //Number(prompt('2번')) - const length3 = 300 //Number(prompt('3번')) - const length4 = 200 //Number(prompt('3번')) - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { - x: pointer.x - length1 / 2, - y: pointer.y + length3 / 2, - }, - { - x: pointer.x - length1 / 2 + (length1 - length2) / 2, - y: pointer.y + length3 / 2 - (length3 - length4), - }, - { - x: pointer.x - length1 / 2 + (length1 - length2) / 2, - y: pointer.y + length3 / 2 - (length3 - length4) - length4, - }, - { - x: pointer.x - length1 / 2 + (length1 - length2) / 2 + length2, - y: pointer.y + length3 / 2 - (length3 - length4) - length4, - }, - { - x: pointer.x - length1 / 2 + (length1 - length2) / 2 + length2, - y: pointer.y + length3 / 2 - (length3 - length4) - length4 + length4, - }, - { - x: pointer.x - length1 / 2 + length1, - y: pointer.y + length3 / 2, - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate26 = () => { - const length1 = 500 //Number(prompt('1번')) - const length2 = 200 //Number(prompt('2번')) - const length3 = 300 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('3번')) - - const angle = (Math.asin(length3 / length4) * 180) / Math.PI // 높이와 빗변으로 먼저 각도구하기 - - const topL = (length1 - length2) / 2 / Math.cos((angle * Math.PI) / 180) // 꺽이는부분 윗쪽 길이 - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { - x: pointer.x - length1 / 2 + length1, - y: pointer.y + length3 / 2, - }, - { - x: pointer.x - length1 / 2, - y: pointer.y + length3 / 2, - }, - { - x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)), - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), - }, - { - x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)) + length2, - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), - }, - { - x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)) + length2 + topL * Math.cos(degreesToRadians(angle)), - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)) + topL * Math.sin(degreesToRadians(angle)), - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate27 = () => { - const length1 = 500 //Number(prompt('1번')) - const length2 = 200 //Number(prompt('2번')) - const length3 = 300 //Number(prompt('3번')) - const length4 = 400 //Number(prompt('3번')) - - const angle = (Math.asin(length3 / length4) * 180) / Math.PI // 높이와 빗변으로 먼저 각도구하기 - - const topL = (length1 - length2) / 2 / Math.cos((angle * Math.PI) / 180) // 꺽이는부분 윗쪽 길이 - - let isDrawing = true - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const triangle = new QPolygon( - [ - { - x: pointer.x - length1 / 2, - y: pointer.y + length3 / 2, - }, - { - x: pointer.x - length1 / 2 + length1, - y: pointer.y + length3 / 2, - }, - { - x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)), - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), - }, - { - x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)) - length2, - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), - }, - { - x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)) - length2 - topL * Math.cos(degreesToRadians(angle)), - y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)) + topL * Math.sin(degreesToRadians(angle)), - }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(triangle) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - }) - } - const createTemplate28 = () => { - const length1 = Number(prompt('밑변')) - const length2 = Number(prompt('높이')) - const length3 = Number(prompt('빗변')) - - const a = Math.sqrt(length3 * length3 - length2 * length2) // 입력된 밑변과 높이 - - const sinA = a / length3 - const angleInRadians = Math.asin(sinA) - const angleInDegrees = angleInRadians * (180 / Math.PI) - const b = a - length1 / 2 - - const c = b / Math.tan(angleInRadians) - const d = Math.sqrt(b * b + c * c) - - if (isNaN(a)) { - alert('값이 잘못되었습니다.') - return - } - if (b < 0) { - alert('값이 잘못되었습니다.') - return - } - if (angleInDegrees === 0 || angleInRadians === 0) { - alert('값이 잘못되었습니다.') - return - } - - let isDrawing = true - let pentagon - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const newAngleInRadians = (90 - angleInDegrees) * (Math.PI / 180) - - pentagon = new QPolygon( - [ - { x: pointer.x - (length1 + b) / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2 - b / 2, y: pointer.y + length2 / 2 }, - { - x: pointer.x + length1 / 2 - b / 2 + d * Math.cos(newAngleInRadians), - y: pointer.y + length2 / 2 - d * Math.sin(newAngleInRadians), - }, - { - x: pointer.x - (length1 + b) / 2 + length3 * Math.cos(newAngleInRadians), - y: pointer.y + length2 / 2 - length3 * Math.sin(newAngleInRadians), - }, - ], - { - fill: 'transparent', - stroke: 'gray', - strokeWidth: 1, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(pentagon) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - pentagon.set('name', 'roof') - pentagon.set('stroke', 2) - canvas?.renderAll() - }) - } - const createTemplate29 = () => { - const length1 = Number(prompt('밑변')) - const length2 = Number(prompt('높이')) - const length3 = Number(prompt('빗변')) - - const a = Math.sqrt(length3 * length3 - length2 * length2) // 입력된 밑변과 높이 - - const sinA = a / length3 - const angleInRadians = Math.asin(sinA) - const angleInDegrees = angleInRadians * (180 / Math.PI) - const b = a - length1 / 2 - - const c = b / Math.tan(angleInRadians) - const d = Math.sqrt(b * b + c * c) - - if (isNaN(a)) { - alert('값이 잘못되었습니다.') - return - } - if (b < 0) { - alert('값이 잘못되었습니다.') - return - } - if (angleInDegrees === 0 || angleInRadians === 0) { - alert('값이 잘못되었습니다.') - return - } - - let isDrawing = true - let pentagon - canvas?.on('mouse:move', (e) => { - if (!isDrawing) { - return - } - canvas?.remove(...canvas?.getObjects().filter((obj) => obj.name === 'guideTriangle')) - const pointer = canvas?.getPointer(e.e) - const newAngleInRadians = (90 - angleInDegrees) * (Math.PI / 180) - - pentagon = new QPolygon( - [ - { - x: pointer.x + length1 / 2 - b / 2 - length3 * Math.cos(newAngleInRadians), - y: pointer.y + length2 / 2 - length3 * Math.sin(newAngleInRadians), - }, - { x: pointer.x + length1 / 2 - b / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x - (length1 + b) / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x - (length1 + b) / 2 - d * Math.cos(newAngleInRadians), y: pointer.y + length2 / 2 - d * Math.sin(newAngleInRadians) }, - ], - { - fill: 'transparent', - stroke: 'gray', - strokeWidth: 1, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) - - canvas?.add(pentagon) - }) - - canvas?.on('mouse:down', (e) => { - isDrawing = false - pentagon.set('name', 'roof') - pentagon.set('stroke', 2) - canvas?.renderAll() - }) - } - const moduleConfiguration = () => { createRoofRack() } @@ -1675,60 +759,6 @@ export default function Roof2(props) { - - - - - - - - - - - - - - - - - - diff --git a/src/components/ui/SurfaceShape.jsx b/src/components/ui/SurfaceShape.jsx index 6a5147c8..774f8e28 100644 --- a/src/components/ui/SurfaceShape.jsx +++ b/src/components/ui/SurfaceShape.jsx @@ -4,6 +4,7 @@ import { useRecoilValue, useSetRecoilState } from 'recoil' import { modalState } from '@/store/modalAtom' import { QPolygon } from '@/components/fabric/QPolygon' import { fontSizeState, roofMaterialState } from '@/store/canvasAtom' +import { degreesToRadians } from '@turf/turf' /** * 면형상 배치 모달 @@ -40,6 +41,7 @@ export const SurfaceShapeModal = ({ canvas }) => { const onSave = () => { let isDrawing = true let obj = null + let points = [] canvas?.on('mouse:move', (e) => { if (!isDrawing) { return @@ -54,210 +56,420 @@ export const SurfaceShapeModal = ({ canvas }) => { newLength2 = Math.sqrt(length3 ** 2 - (length1 / 2) ** 2) } - obj = new QPolygon( - [ - { x: pointer.x, y: pointer.y - parseInt(newLength2) / 2 }, - { x: pointer.x - parseInt(length1) / 2, y: pointer.y + parseInt(newLength2) / 2 }, - { x: pointer.x + parseInt(length1) / 2, y: pointer.y + parseInt(newLength2) / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x, y: pointer.y - parseInt(newLength2) / 2 }, + { x: pointer.x - parseInt(length1) / 2, y: pointer.y + parseInt(newLength2) / 2 }, + { x: pointer.x + parseInt(length1) / 2, y: pointer.y + parseInt(newLength2) / 2 }, + ] break } case 2: { - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y - length2 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y - length2 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, + ] + break } case 3: { - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length3 / 2, y: pointer.y - length2 / 2 }, - { x: pointer.x - length3 / 2, y: pointer.y - length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length3 / 2, y: pointer.y - length2 / 2 }, + { x: pointer.x - length3 / 2, y: pointer.y - length2 / 2 }, + ] + break } case 4: { - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y - length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y - length2 / 2 }, + ] break } case 5: { - obj = new QPolygon( - [ - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, + ] + break } case 6: { - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y - length3 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 - length2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y - length3 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 - length2 }, + ] + break } case 7: { - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 - length3 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y - length2 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 - length3 }, + ] + break } case 8: { const angleInRadians = Math.asin(length2 / length3) - obj = new QPolygon( - [ - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x - length1 / 2 + length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, - { x: pointer.x + length1 / 2 + length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x - length1 / 2 + length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, + { x: pointer.x + length1 / 2 + length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + ] + break } case 9: { const angleInRadians = Math.asin(length2 / length3) - obj = new QPolygon( - [ - { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, - { x: pointer.x + length1 / 2 - length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, - { x: pointer.x - length1 / 2 - length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, - { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, - ], - { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: false, - fontSize: fontSize, - name: 'guideTriangle', - }, - ) + points = [ + { x: pointer.x + length1 / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2 - length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, + { x: pointer.x - length1 / 2 - length3 * Math.cos(angleInRadians), y: pointer.y + length2 / 2 - length3 * Math.sin(angleInRadians) }, + { x: pointer.x - length1 / 2, y: pointer.y + length2 / 2 }, + ] + break } case 10: { - console.log(length1, length2, length3, length4, length5) - obj = new QPolygon( - [ - { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y - (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y + (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 - length5 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 }, - { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 + length5 }, - { - x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, - y: pointer.y + (length4 + length5) / 2 - length5 + length5, - }, - { - x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, - y: pointer.y + (length4 + length5) / 2 - length5 + length5 - (length4 + length5), - }, - ], + points = [ + { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y - (length4 + length5) / 2 }, + { x: pointer.x - (length1 + length2 + length3) / 2, y: pointer.y + (length4 + length5) / 2 }, + { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 }, + { x: pointer.x - (length1 + length2 + length3) / 2 + length1, y: pointer.y + (length4 + length5) / 2 - length5 }, + { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 }, + { x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2, y: pointer.y + (length4 + length5) / 2 - length5 + length5 }, { - fill: 'transparent', - stroke: 'black', - strokeWidth: 2, - selectable: true, - fontSize: fontSize, - name: 'guideTriangle', + x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, + y: pointer.y + (length4 + length5) / 2 - length5 + length5, }, - ) + { + x: pointer.x - (length1 + length2 + length3) / 2 + length1 + length2 + length3, + y: pointer.y + (length4 + length5) / 2 - length5 + length5 - (length4 + length5), + }, + ] + + break + } + case 11: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length3 }, + { x: pointer.x - length1 / 2 + length1 - (length1 - length2), y: pointer.y + length4 / 2 - length3 }, + { x: pointer.x - length1 / 2 + length1 - (length1 - length2), y: pointer.y + length4 / 2 - length3 + (length3 - length4) }, + { x: pointer.x - length1 / 2 + length1 - (length1 - length2) - length2, y: pointer.y + length4 / 2 - length3 + (length3 - length4) }, + ] + + break + } + case 12: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length4 - (length3 - length4) }, + { x: pointer.x - length1 / 2 + length1 - length2 - (length1 - length2), y: pointer.y + length4 / 2 - length4 - (length3 - length4) }, + ] + + break + } + case 13: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, + { x: pointer.x - length1 / 2 + length1 - length3 - length2, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, + ] + break + } + case 14: { + points = [ + { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x + length1 / 2 - length1 + length3, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x + length1 / 2 - length1 + length3, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, + { x: pointer.x + length1 / 2 - length1 + length3 + length2, y: pointer.y + length4 / 2 - length4 + (length4 - length5) }, + ] + break + } + case 15: { + points = [ + { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + { x: pointer.x + length1 / 2 - length1 + length2 + length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + ] + break + } + case 16: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + { x: pointer.x - length1 / 2 + length1 - length2 - length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + ] + break + } + case 17: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x - length1 / 2 + length1 - length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + { x: pointer.x - length1 / 2 + length1 - length2 - length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + ] + break + } + case 18: { + points = [ + { x: pointer.x + length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 }, + { x: pointer.x + length1 / 2 - length1, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 }, + { x: pointer.x + length1 / 2 - length1 + length2, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + { x: pointer.x + length1 / 2 - length1 + length2 + length3, y: pointer.y + length4 / 2 - length5 - (length4 - length5) }, + ] + break + } + + case 19: { + const leftHypotenuse = Math.sqrt(((length1 - length2) / 2) ** 2 + length3 ** 2) + const rightHypotenuse = (length4 / length3) * leftHypotenuse + + const leftAngle = Math.acos((length1 - length2) / 2 / leftHypotenuse) + + points = [ + { x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(leftAngle), y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(leftAngle) }, + { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, + { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, + { + x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(leftAngle), + y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(leftAngle), + }, + { + x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(leftAngle) - length2, + y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(leftAngle), + }, + ] + + break + } + case 20: { + // 좌측 빗변 + const rightHypotenuse = Math.sqrt(((length1 - length2) / 2) ** 2 + length3 ** 2) + const leftHypotenuse = (length4 / length3) * rightHypotenuse + + const rightAngle = Math.acos((length1 - length2) / 2 / rightHypotenuse) + points = [ + { + x: pointer.x + length1 / 2 - rightHypotenuse * Math.cos(rightAngle), + y: pointer.y + length3 / 2 - rightHypotenuse * Math.sin(rightAngle), + }, + { x: pointer.x + length1 / 2, y: pointer.y + length3 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length3 / 2 }, + { + x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(rightAngle), + y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(rightAngle), + }, + { + x: pointer.x - length1 / 2 + leftHypotenuse * Math.cos(rightAngle) + length2, + y: pointer.y + length3 / 2 - leftHypotenuse * Math.sin(rightAngle), + }, + ] + break + } + + case 23: { + points = [ + { x: pointer.x - length1 / 2 + length2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 }, + { x: pointer.x - length1 / 2 + length1, y: pointer.y + length4 / 2 - length4 + length4 }, + { x: pointer.x - length1 / 2 + length1 - length3, y: pointer.y + length4 / 2 - length4 + length4 }, + { x: pointer.x - length1 / 2 + length2 + (length1 - length2 - length3) / 2, y: pointer.y + length4 / 2 - length4 + length5 }, + ] + break + } + + case 24: { + points = [ + { x: pointer.x - length1 / 2, y: pointer.y + length2 - length2 / 2 }, + { x: pointer.x - length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 }, + { x: pointer.x, y: pointer.y + length2 - length2 / 2 - length3 - (length2 - length3) }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 }, + { x: pointer.x + length1 / 2, y: pointer.y + length2 - length2 / 2 - length3 + length3 }, + ] + break + } + + case 25: { + points = [ + { + x: pointer.x - length1 / 2, + y: pointer.y + length3 / 2, + }, + { + x: pointer.x - length1 / 2 + (length1 - length2) / 2, + y: pointer.y + length3 / 2 - (length3 - length4), + }, + { + x: pointer.x - length1 / 2 + (length1 - length2) / 2, + y: pointer.y + length3 / 2 - (length3 - length4) - length4, + }, + { + x: pointer.x - length1 / 2 + (length1 - length2) / 2 + length2, + y: pointer.y + length3 / 2 - (length3 - length4) - length4, + }, + { + x: pointer.x - length1 / 2 + (length1 - length2) / 2 + length2, + y: pointer.y + length3 / 2 - (length3 - length4) - length4 + length4, + }, + { + x: pointer.x - length1 / 2 + length1, + y: pointer.y + length3 / 2, + }, + ] + break + } + case 26: { + const angle = (Math.asin(length3 / length4) * 180) / Math.PI // 높이와 빗변으로 먼저 각도구하기 + + const topL = (length1 - length2) / 2 / Math.cos((angle * Math.PI) / 180) // 꺽이는부분 윗쪽 길이 + + points = [ + { + x: pointer.x - length1 / 2 + length1, + y: pointer.y + length3 / 2, + }, + { + x: pointer.x - length1 / 2, + y: pointer.y + length3 / 2, + }, + { + x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)), + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), + }, + { + x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)) + length2, + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), + }, + { + x: pointer.x - length1 / 2 + length4 * Math.cos(degreesToRadians(angle)) + length2 + topL * Math.cos(degreesToRadians(angle)), + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)) + topL * Math.sin(degreesToRadians(angle)), + }, + ] + break + } + case 27: { + const angle = (Math.asin(length3 / length4) * 180) / Math.PI // 높이와 빗변으로 먼저 각도구하기 + + const topL = (length1 - length2) / 2 / Math.cos((angle * Math.PI) / 180) // 꺽이는부분 윗쪽 길이 + points = [ + { + x: pointer.x - length1 / 2, + y: pointer.y + length3 / 2, + }, + { + x: pointer.x - length1 / 2 + length1, + y: pointer.y + length3 / 2, + }, + { + x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)), + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), + }, + { + x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)) - length2, + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)), + }, + { + x: pointer.x - length1 / 2 + length1 - length4 * Math.cos(degreesToRadians(angle)) - length2 - topL * Math.cos(degreesToRadians(angle)), + y: pointer.y + length3 / 2 - length4 * Math.sin(degreesToRadians(angle)) + topL * Math.sin(degreesToRadians(angle)), + }, + ] + break + } + case 28: { + const a = Math.sqrt(length3 * length3 - length2 * length2) // 입력된 밑변과 높이 + + const sinA = a / length3 + const angleInRadians = Math.asin(sinA) + const angleInDegrees = angleInRadians * (180 / Math.PI) + const b = a - length1 / 2 + + const c = b / Math.tan(angleInRadians) + const d = Math.sqrt(b * b + c * c) + const newAngleInRadians = (90 - angleInDegrees) * (Math.PI / 180) + points = [ + { x: pointer.x - (length1 + b) / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x + length1 / 2 - b / 2, y: pointer.y + length2 / 2 }, + { + x: pointer.x + length1 / 2 - b / 2 + d * Math.cos(newAngleInRadians), + y: pointer.y + length2 / 2 - d * Math.sin(newAngleInRadians), + }, + { + x: pointer.x - (length1 + b) / 2 + length3 * Math.cos(newAngleInRadians), + y: pointer.y + length2 / 2 - length3 * Math.sin(newAngleInRadians), + }, + ] + break + } + case 29: { + const a = Math.sqrt(length3 * length3 - length2 * length2) // 입력된 밑변과 높이 + + const sinA = a / length3 + const angleInRadians = Math.asin(sinA) + const angleInDegrees = angleInRadians * (180 / Math.PI) + const b = a - length1 / 2 + + const c = b / Math.tan(angleInRadians) + const d = Math.sqrt(b * b + c * c) + const newAngleInRadians = (90 - angleInDegrees) * (Math.PI / 180) + points = [ + { + x: pointer.x + length1 / 2 - b / 2 - length3 * Math.cos(newAngleInRadians), + y: pointer.y + length2 / 2 - length3 * Math.sin(newAngleInRadians), + }, + { x: pointer.x + length1 / 2 - b / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x - (length1 + b) / 2, y: pointer.y + length2 / 2 }, + { x: pointer.x - (length1 + b) / 2 - d * Math.cos(newAngleInRadians), y: pointer.y + length2 / 2 - d * Math.sin(newAngleInRadians) }, + ] break } } + obj = new QPolygon(points, { + fill: 'transparent', + stroke: 'black', + strokeWidth: 2, + selectable: false, + fontSize: fontSize, + name: 'guideTriangle', + }) canvas?.add(obj) setCurrentPattern(obj) canvas?.renderAll() @@ -332,40 +544,25 @@ export const SurfaceShapeModal = ({ canvas }) => { canvas?.renderAll() } + const ButtonComp = () => { + // Generate 29 buttons + const buttons = [] + for (let i = 1; i <= 29; i++) { + buttons.push( + , + ) + } + + return