简体   繁体   中英

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?

EDIT

  • The radius is specified
  • Number of line segments may vary, but there are 2 lines at least
  • Lines start at starting border, end at the ending border; eg: Start is C , end point is 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,

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.

"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 +/-).

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}); } 

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.

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