다각형 모임지붕 계산 중

This commit is contained in:
Jaeyoung Lee 2024-08-06 14:44:27 +09:00
parent a859aa26e8
commit d2195e9fc2
3 changed files with 25 additions and 12 deletions

View File

@ -275,7 +275,7 @@ export default function Roof2() {
{ x: 450, y: 850 }, { x: 450, y: 850 },
] ]
const polygon = new QPolygon(type1, { const polygon = new QPolygon(twelvePoint, {
fill: 'transparent', fill: 'transparent',
stroke: 'green', stroke: 'green',
strokeWidth: 1, strokeWidth: 1,

View File

@ -356,6 +356,6 @@ export const QPolygon = fabric.util.createClass(fabric.Polygon, {
}) })
}, },
divideLine() { divideLine() {
//dividePolygon(this) dividePolygon(this)
}, },
}) })

View File

@ -1,13 +1,6 @@
import { fabric } from 'fabric' import { fabric } from 'fabric'
import { QLine } from '@/components/fabric/QLine' import { QLine } from '@/components/fabric/QLine'
import { import { calculateIntersection, distanceBetweenPoints, findClosestPoint, getDirectionByPoint } from '@/util/canvas-util'
calculateIntersection,
distanceBetweenPoints,
findClosestPoint,
getAdjacent,
getDirectionByPoint,
getRoofHypotenuse,
} from '@/util/canvas-util'
import { QPolygon } from '@/components/fabric/QPolygon' import { QPolygon } from '@/components/fabric/QPolygon'
const TWO_PI = Math.PI * 2 const TWO_PI = Math.PI * 2
@ -1460,6 +1453,17 @@ const drawHips = (polygon) => {
polygon.innerLines.push(hip) polygon.innerLines.push(hip)
} }
if (rightTop !== undefined) { if (rightTop !== undefined) {
console.log('rightTop : ', rightTop)
polygon.ridges.forEach((r) => {
if (r.x1 > ridge.x1 && r.y1 < ridge.y1) {
console.log('ridge : ', r)
console.log((r.y1 - rightTop.y1) * (ridge.x1 - rightTop.x1) === (r.x1 - rightTop.x1) * (ridge.y1 - rightTop.y1))
}
if (r.x2 > ridge.x1 && r.y2 < ridge.y1) {
console.log('ridge : ', r)
console.log((r.y2 - rightTop.y1) * (ridge.x1 - rightTop.x1) === (r.x2 - rightTop.x1) * (ridge.y1 - rightTop.y1))
}
})
const hip = new QLine([rightTop.x1, rightTop.y1, ridge.x1, ridge.y1], { const hip = new QLine([rightTop.x1, rightTop.y1, ridge.x1, ridge.y1], {
fontSize: polygon.fontSize, fontSize: polygon.fontSize,
stroke: 'red', stroke: 'red',
@ -1495,7 +1499,7 @@ const drawHips = (polygon) => {
console.log('polygon.hips : ', polygon.hips) console.log('polygon.hips : ', polygon.hips)
// 가장 가까운 마루를 확인하여 그릴 수 있는 라인이 존재하면 먼저 그린다. // 가장 가까운 마루를 확인하여 그릴 수 있는 라인이 존재하면 먼저 그린다.
let prevLine, currentLine, nextLine /*let prevLine, currentLine, nextLine
polygon.lines.forEach((value, index) => { polygon.lines.forEach((value, index) => {
if (index === 0) { if (index === 0) {
prevLine = polygon.lines[polygon.lines.length - 1] prevLine = polygon.lines[polygon.lines.length - 1]
@ -1854,10 +1858,19 @@ const drawHips = (polygon) => {
polygon.hips.push(hip) polygon.hips.push(hip)
polygon.innerLines.push(hip) polygon.innerLines.push(hip)
} }
}) })*/
// this.canvas.renderAll() // this.canvas.renderAll()
} }
const isRidgePointOnLine = (polygon, x1, y1, x2, y2) => {
let isRidgePointOnLine = false
polygon.ridges.forEach((ridge) => {
console.log((ridge.y1 - rightTop.y1) * (ridge.x1 - rightTop.x1) === (ridge.x1 - rightTop.x1) * (ridge.y1 - rightTop.y1))
console.log((ridge.y2 - rightTop.y1) * (ridge.x1 - rightTop.x1) === (ridge.x2 - rightTop.x1) * (ridge.y1 - rightTop.y1))
})
}
const getPointInPolygon = (polygon, point) => { const getPointInPolygon = (polygon, point) => {
let inside = false let inside = false
let minX = Math.min(polygon[0].x, polygon[1].x, polygon[2].x, polygon[3].x), let minX = Math.min(polygon[0].x, polygon[1].x, polygon[2].x, polygon[3].x),