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

Fix planarIntersect formula in MPAS mesh converter #567

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions mesh_tools/mesh_conversion_tools/pnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,27 @@ pnt planarIntersect(const pnt &c1, const pnt &c2, const pnt &v1, const pnt &v2){
* planarIntersect is intended to compute the point of intersection
* of the lines c1-c2 and v1-v2 in a plane.
*/
double alpha_numerator, beta_numerator, denom;
double alpha, beta;
double cx_numerator, cy_numerator, denom;
pnt c;

alpha_numerator = (v2.x - v1.x) * (c1.y - v2.y) - (v2.y - v1.y) * (c1.x - v2.x);
// beta_numerator = (c1.x - v2.x) * (c2.y - c1.y) - (c1.y - v2.y) * (c2.x - c1.x);
denom = (c2.x - c1.x) * (v2.y - v1.y) - (c2.y - c1.y) * (v2.x - v1.x);
double x1 = v1.x;
double y1 = v1.y;

alpha = alpha_numerator / denom;
// beta = beta_numerator / demon;
double x2 = v2.x;
double y2 = v2.y;

c = alpha * (v2 - v1) + v1;
double x3 = c1.x;
double y3 = c1.y;

double x4 = c2.x;
double y4 = c2.y;

cx_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
cy_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);

c.x = cx_numerator / denom;
c.y = cy_numerator / denom;

return c;
}/*}}}*/
Expand Down
25 changes: 17 additions & 8 deletions mesh_tools/mesh_conversion_tools_netcdf_c/pnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,27 @@ pnt planarIntersect(const pnt &c1, const pnt &c2, const pnt &v1, const pnt &v2){
* planarIntersect is intended to compute the point of intersection
* of the lines c1-c2 and v1-v2 in a plane.
*/
double alpha_numerator, beta_numerator, denom;
double alpha, beta;
double cx_numerator, cy_numerator, denom;
pnt c;

alpha_numerator = (v2.x - v1.x) * (c1.y - v2.y) - (v2.y - v1.y) * (c1.x - v2.x);
// beta_numerator = (c1.x - v2.x) * (c2.y - c1.y) - (c1.y - v2.y) * (c2.x - c1.x);
denom = (c2.x - c1.x) * (v2.y - v1.y) - (c2.y - c1.y) * (v2.x - v1.x);
double x1 = v1.x;
double y1 = v1.y;

alpha = alpha_numerator / denom;
// beta = beta_numerator / demon;
double x2 = v2.x;
double y2 = v2.y;

c = alpha * (v2 - v1) + v1;
double x3 = c1.x;
double y3 = c1.y;

double x4 = c2.x;
double y4 = c2.y;

cx_numerator = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4);
cy_numerator = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4);
denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);

c.x = cx_numerator / denom;
c.y = cy_numerator / denom;

return c;
}/*}}}*/
Expand Down