Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question around room area calculation #229

Open
ammanvedi opened this issue Sep 26, 2021 · 1 comment
Open

Question around room area calculation #229

ammanvedi opened this issue Sep 26, 2021 · 1 comment

Comments

@ammanvedi
Copy link

graph-cycles.js line 237, can anyone help me with the significance of this line

    return (V[v2][0]  - V[v1][0]) * (V[v2][1] + V[v1][1]);

i understand we take the positions for the start aned end of an edge, and the first bracketed term i think gives the length of the edge but why do we then multiply this by the sum of the y coordinate of the start and end position ?

it is used to eliminate certain cycles from the final result but otherwise im not sure

@ammanvedi
Copy link
Author

ammanvedi commented Sep 26, 2021

Ah ok so i have found the code for determining ordering

export function isClockWiseOrder(innerCycleWithCoords) {
  // See: https://stackoverflow.com/a/1165943 and http://blog.element84.com/polygon-winding.html

  let i = 0;
  let twiceEnclosedArea = 0;
  let size = innerCycleWithCoords.size;

  for (i = 0; i < size; i++) {

    let { x: x1, y: y1 } = innerCycleWithCoords.get(i);
    let { x: x2, y: y2 } = innerCycleWithCoords.get((i + 1) % size);

    twiceEnclosedArea += (x2 - x1) * (y2 + y1);
  }

  return twiceEnclosedArea > 0;
}

With the helpful links that show the summation

Screenshot 2021-09-26 at 21 48 38

so this makes sense now, it is the area calculation, but because we are only interested in the sign and not the actual value we can omit the 1/2.

i assume that in the following lines

  let rooms_sums = rooms_values.map(room => room.reduce((a, b) => a + b))

  let positive_count = rooms_sums.filter(sum => sum > 0).length;
  let negative_count = rooms_sums.length - positive_count;

  let rm_neg =  positive_count >= negative_count ? 1 : -1;

  return {
    v_cycles: cycles.v_cycles.filter((v, i) => (rm_neg * rooms_sums[i]) > 0 ),
    e_cycles: cycles.e_cycles.filter((v, i) => (rm_neg * rooms_sums[i]) > 0 ),
    ev_mapping: cycles.ev_mapping
  }

we have to identify the paths that define the boundaries of the shapes so they can be excluded

the areas of the boundaries will differ from the areas of the internal shapes as they will be negative and the internal faces positve, or vice versa

we also assume that there will be more internal faces than boundaries

therefore whichever type of value is more prevelant positive or negative are the internal faces we are interested in

this is how we eliminate the boundary.

What i am struggling with is;

  1. is there any pseudo code algorithm for this process that anyone knows of
  2. why would the boundary face have an area with a different sign, im guessing the vertex traversal ordering is different, but why
  3. are all the points i made above actually correct XD

anyway ill continue to try and understand but i just want to put this here in case anyone can save me some time XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant