简体   繁体   English

如何获得弧线的交点?

[英]How to get the intersection points of an Arc and a line?

I need to place several number of line segments inside an arc, but to do that i need to have intersection points so that i can place the lines inside the arc perfectly; 我需要在弧内放置多个线段,但要做到这一点,我需要有交点,以便可以将线完美地放置在弧内。

在此处输入图片说明

I thought about a way to calculate the distance and check if it is less than radius, but the thing is i need to know the C,D & E points so that i can place the line segments, so i'm lost here, any one can help please? 我想过一种计算距离并检查距离是否小于半径的方法,但是我需要知道C,D和E点,以便可以放置线段,所以我在这里迷路了一个可以帮忙吗?

EDIT 编辑

  • The radius is specified 指定半径
  • Number of line segments may vary, but there are 2 lines at least 线段的数量可能有所不同,但至少有2条线
  • Lines start at starting border, end at the ending border; 线从起始边界开始,在终止边界结束; eg: Start is C , end point is D 例如:起点是C ,终点是D

EDIT In order to be clear about what i'm trying to do, i'm uploading another illustration; 编辑为了弄清楚我要做什么,我正在上传另一个插图。 在此处输入图片说明

I need to get the coordinates of [CD],[EI],[JK] lines, 我需要获取[CD],[EI],[JK]行的坐标,

Ok... Here we go. 好吧...我们走了。 The following snippet should work for any arc (defined with an angle and a radius) and for any number of equally spaced segments you want. 以下代码段适用于任何圆弧(使用角度和半径定义)以及所需的任意数量的等距段。

Currently, it assumes that the arc is perfectly placed horizontally (like in your example), but it can be "easily" extended to allow translated/rotated arcs. 当前,它假定圆弧完美地水平放置(如您的示例中所示),但是可以“轻松”扩展它以允许平移/旋转的圆弧。

The getLinesCoords() function will return an object whose x and y properties contains arrays with the corresponding coordinates for each segment. getLinesCoords()函数将返回一个对象,该对象的xy属性包含每个段具有相应坐标的数组。

"y" coordinates are the "height" of the segment from the center (G in your image) and "x" are the start/end position, always from center (left/right depends on sign +/-). “ y”坐标是距中心(图像中的G)的线段的“高度”,“ x”是起始/结束位置,始终是距中心的位置(左/右取决于符号+/-)。

If you have any question, please ask. 如有任何疑问,请询问。

 // *** ARC *** const R = 100; // RADIUS const PHI = 180; // ANGLE (DEG) // *** LINES *** const LINES = 10; // NUMBER OF LINES TO BE PLACED // *** CALCULATIONS *** const coords = getLinesCoords(R, PHI, LINES); console.log(coords); function getLinesCoords(radius, angle, linesNum) { let i = 0; let arcAvailHeight = 0; let linesSep = 0; let linesYCoords = []; let linesXCoords = []; let angleRad = angle * Math.PI / 180; // GET AVAILABLE HEIGHT FOR PLACING LINES arcAvailHeight = radius * (1 - Math.cos(angleRad / 2)); // GET LINES SEPARATION linesSep = arcAvailHeight / (linesNum + 1); // GET Y COORDINATES FOR LINES for (i = 0; i < linesNum; i++) { linesYCoords[i] = linesSep * (i + 1); } // GET CORRESPONDING X COORDINATES FOR LINES linesYCoords.forEach((y) => { linesXCoords.push(Math.sqrt(radius**2 - (radius * Math.cos(angleRad / 2) + y)**2)); }); return ({x: linesXCoords, y: linesYCoords}); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM