1
0
Fork 0
freesewing/packages/examples/src/utils_lineintersectscircle.js

46 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import { box } from './shared'
2019-05-25 11:11:46 +02:00
2021-01-31 09:22:15 +01:00
export default (part) => {
2019-08-03 15:03:33 +02:00
let { Point, points, Path, paths, Snippet, snippets, utils } = part.shorthand()
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
points.A = new Point(95, 45).attr('data-circle', 35).attr('data-circle-class', 'fabric')
points.B = new Point(55, 50)
points.C = new Point(75, 30)
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
points.D = new Point(55, 65)
points.E = new Point(115, 5)
points.F = new Point(65, 75)
points.G = new Point(125, 15)
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
paths.line1 = new Path().move(points.B).line(points.C)
paths.line2 = new Path().move(points.D).line(points.E)
paths.line3 = new Path().move(points.F).line(points.G)
2019-01-27 12:54:18 +01:00
let intersections1 = utils.lineIntersectsCircle(
points.A,
2019-08-03 15:03:33 +02:00
points.A.attributes.get('data-circle'),
2019-01-27 12:54:18 +01:00
points.B,
points.C
2019-08-03 15:03:33 +02:00
)
2019-01-27 12:54:18 +01:00
let intersections2 = utils.lineIntersectsCircle(
points.A,
2019-08-03 15:03:33 +02:00
points.A.attributes.get('data-circle'),
2019-01-27 12:54:18 +01:00
points.D,
points.E,
2019-08-03 15:03:33 +02:00
'y'
)
2019-01-27 12:54:18 +01:00
let intersections3 = utils.lineIntersectsCircle(
points.A,
2019-08-03 15:03:33 +02:00
points.A.attributes.get('data-circle'),
2019-01-27 12:54:18 +01:00
points.F,
points.G
2019-08-03 15:03:33 +02:00
)
snippets.first1 = new Snippet('bnotch', intersections1[0])
snippets.first2 = new Snippet('bnotch', intersections2[0])
snippets.second2 = new Snippet('notch', intersections2[1])
snippets.first3 = new Snippet('bnotch', intersections3[0])
snippets.second3 = new Snippet('notch', intersections3[1])
2019-01-27 12:54:18 +01:00
2019-08-03 15:03:33 +02:00
return box(part, 200, 80)
}