gctl/lib/geometry/geometry2d.h

244 lines
9.2 KiB
C
Raw Normal View History

2024-09-10 15:45:07 +08:00
/********************************************************
*
*
*
*
*
*
* Geophysical Computational Tools & Library (GCTL)
*
* Copyright (c) 2023 Yi Zhang (yizhang-geo@zju.edu.cn)
*
* GCTL is distributed under a dual licensing scheme. You can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 2
* of the License, or (at your option) any later version. You should have
* received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
*
* If the terms and conditions of the LGPL v.2. would prevent you from using
* the GCTL, please consider the option to obtain a commercial license for a
* fee. These licenses are offered by the GCTL's original author. As a rule,
* licenses are provided "as-is", unlimited in time for a one time fee. Please
* send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget
* to include some description of your company and the realm of its activities.
* Also add information on how to contact you by electronic and paper mail.
******************************************************/
#ifndef _GCTL_GEOMETRY2D_H
#define _GCTL_GEOMETRY2D_H
// library's head files
#include "../core/array.h"
#include "../maths.h"
#include "triangle2d.h"
#include "triangle2d2o.h"
#include "edge2d.h"
#include "rectangle2d.h"
namespace gctl
{
namespace geometry2d
{
/**
* @brief t是否在直线ab上
*
* @param[in] a a
* @param[in] b b
* @param[in] t t
* @param[in] cut_off
*
* @return t是否在直线ab上
*/
bool collinear(const point2dc &a, const point2dc &b, const point2dc &t,
double cut_off = GCTL_ZERO);
/**
* @brief 线线线
*
* @note 线 p1->p2
*
* @param[in] p1 线线
* @param[in] p2 线线
* @param[in] out_p 线
* @param on_p out_p 线
*
* @return 线
*/
bool dot_on_line(const point2dc &p1, const point2dc &p2, const point2dc &out_p, point2dc &on_p);
// 求两条直线的交点。
/**
* @brief 线
*
* @note 线out值将无变化
*
* @param[in] l1_p1 线1
* @param[in] l1_p2 线1
* @param[in] l2_p1 线2
* @param[in] l2_p2 线2
* @param out
*/
void line_intersect(const point2dc &l1_p1, const point2dc &l1_p2, const point2dc &l2_p1, const point2dc &l2_p2, point2dc &out);
/**
* @brief 线
*
* @param[in] l1_p1 线1
* @param[in] l1_p2 线1
* @param[in] l2_p1 线2
* @param[in] l2_p2 线2
*
* @return 线(NaN, NaN)
*/
point2dc line_intersect(const point2dc &l1_p1, const point2dc &l1_p2,
const point2dc &l2_p1, const point2dc &l2_p2);
/**
* @brief 线
*
* @param t_p1 1
* @param t_p2 2
* @param t_p3 3
* @param in_p
* @param a1 1
* @param a2 2
* @param a3 3
*/
void tri_split_area(const point2dc &t_p1, const point2dc &t_p2, const point2dc &t_p3, const point2dc &in_p,
double &a1, double &a2, double &a3);
/**
* @brief
*
* @param[in] p
* @param[in] p1 1
* @param[in] p2 2
* @param[in] p3 3
* @param[in] d1 1
* @param[in] d2 2
* @param[in] d3 3
* @param[in] w 2
*
* @return
*/
double tri_interp_dist(const point2dc &p, const point2dc &p1, const point2dc &p2,
const point2dc &p3, double d1, double d2, double d3, double w = 2.0);
/**
* @brief
*
* @param[in] p
* @param[in] p1 1
* @param[in] p2 2
* @param[in] p3 3
* @param[in] d1 1
* @param[in] d2 2
* @param[in] d3 3
*
* @return
*/
double tri_interp_area(const point2dc &p, const point2dc &p1, const point2dc &p2,
const point2dc &p3, double d1, double d2, double d3);
/**
* @brief
*
* @param p1 1
* @param p2 2
* @param p3 3
* @param d1 1
* @param d2 2
* @param d3 3
* @param dx x方向导数
* @param dy y方向导数
*/
void tri_plane_gradient(const point2dc &p1, const point2dc &p2, const point2dc &p3,
const double &d1, const double &d2, const double &d3, double &dx, double &dy);
/**
* @brief
*
* @param test_p
* @param p1
* @param p2
* @param p3
*
* @return
*/
bool node_in_triangle(const point2dc &test_p, const point2dc &p1,
const point2dc &p2, const point2dc &p3, bool on_boundary = true);
/**
* @brief
*
* @param[in] poly_ps
* @param[in] one_p
* @param on_boundary
*
* @return
*/
bool node_in_polygon(const array<point2dc> &poly_ps, const point2dc &one_p, bool on_boundary = true);
/**
* @brief Get common edges of a triangular mesh.
*
* @param[in] input_ele The input elements
* @param out_edge The output edges
*/
void get_common_edges(const array<triangle2d> &input_ele, array<edge2d> &out_edge);
/**
* @brief Get number of vertex of a group of triangles
*
* @param[in] input_ele The input elements
*
* @return Number of vertex
*/
int sort_node_number(const array<triangle2d> &input_ele);
/**
* @brief Sort triangular neighbors for the mesh's vertex
*
* @param[in] input_ele The input element
* @param out_node_neigh The output node's neighbors of triangle
*/
void sort_node_neighbor(const array<triangle2d> &input_ele, std::vector<std::vector<triangle2d*> > &out_node_neigh, int node_num);
/**
* @brief Sort neighbors for triangle elements
*
* @param[in] input_ele The input elements
*/
void sort_triangle_neighbor(array<triangle2d> &input_ele, const std::vector<std::vector<triangle2d*> > &node_neighs);
/**
* @brief 使线
*
* @note 线线p12的射线方向
*
* @param[in] in_eles
* @param[in] p1 线
* @param[in] p2 线
* @param out_nodes
* @param out_eles
*/
void cut_triangular_mesh_2d(const array<triangle2d> &in_eles, const point2dc &p1, const point2dc &p2,
array<vertex2dc> &out_nodes, array<triangle2d> &out_eles);
/**
* @brief
*
* @param[in] in_eles
* @param[in] out_list
* @param out_nodes
* @param out_eles
*/
void extract_triangular_mesh_2d(const array<triangle2d> &in_eles, const array<bool> &out_list,
array<vertex2dc> &out_nodes, array<triangle2d> &out_eles);
}
2025-02-06 21:17:24 +08:00
};
2024-09-10 15:45:07 +08:00
#endif // _GCTL_GEOMETRY2D_H