0
votes

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;

enter image description here

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; e.g: 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; enter image description here

I need to get the coordinates of [CD],[EI],[JK] lines,

1
Graphics Gems by Glassner contains quick code for doing all kinds of math/graphics problems. This book is genious: amazon.com/Graphics-Gems-Andrew-S-Glassner/dp/0122861663Kieveli
How are your arcs defined? (radius + angle?) Do segments need to start at arcs center and end in the arcs border? How many segments or with what distribution/density do you want them?Ernesto Stifano
@ErnestoStifano Line segments start at one border, end at the opposite border. Radius is specified, the number of segments may change, but 2 at least.Ahmet Gokdayi
It is still not clear what you are trying to do... there is no such a thing as “opposite border” in an arc unless it has an angle of 180 degrees or more. In any case, which is the logic to position the segments? Is it random?Ernesto Stifano
Ok, I saw your last edit... do you want to place the segments randomly? Equally spaced? Start from top or bottom?Ernesto Stifano

1 Answers

1
votes

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

}