gctl/lib/geometry/geometry3d.h

366 lines
14 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_GEOMETRY3D_H
#define _GCTL_GEOMETRY3D_H
// library's head file
#include "../core/array.h"
#include "../core/matrix.h"
#include "../maths.h"
#include "tensor.h"
#include "node.h"
#include "edge.h"
#include "tetrahedron.h"
#include "triangle.h"
#include "block.h"
#include "tri_cone.h"
#include "sphere.h"
#include "tesseroid.h"
#include "prism.h"
namespace gctl
{
namespace geometry3d
{
/**
* @brief
*
* @param[in] a a
* @param[in] b b
*
* @return
*/
double angle(const point3dc &a, const point3dc &b);
/**
* @brief
*
* @param a a
* @param b b
* @param c c
* @return double
*/
double triangle_area(const point3dc &a, const point3dc &b, const point3dc &c);
/**
* @brief
*
* @param a a
* @param b b
* @param c c
* @param d d
* @return double
*/
double tetrahedron_volume(const point3dc &a, const point3dc &b, const point3dc &c, const point3dc &d);
/**
* @brief 线
*
* @param[in] line_start 线
* @param[in] line_end 线
* @param[in] dot 线
*
* @return 线
*/
double dot2line(const point3dc &line_start, const point3dc &line_end, const point3dc &dot);
/**
* @brief 线
*
* @param[in] line_start 线
* @param[in] line_end 线
* @param[in] dot 线
*
* @return 线
*/
point3dc dot_on_line(const point3dc &line_start, const point3dc &line_end, const point3dc &dot);
/**
* @brief
*
* @param[in] c
* @param[in] n 线
* @param[in] d
*
* @return
*/
double dot2plane(const point3dc &c, const point3dc &n, const point3dc &d);
/**
* @brief Calculate the coefficients of a 3D plane using coordinates of three points on the plane.
* The plane's equation is given as Ax + By + Cz + D = 0
*
* @param x1 x coordinate of the first point
* @param x2 x coordinate of the second point
* @param x3 x coordinate of the third point
* @param y1 y coordinate of the first point
* @param y2 y coordinate of the second point
* @param y3 y coordinate of the third point
* @param z1 z coordinate of the first point
* @param z2 z coordinate of the second point
* @param z3 z coordinate of the third point
* @param A coefficient A
* @param B coefficient B
* @param C coefficient C
* @param D coefficient D
*/
void get_plane_coeff(double x1, double x2, double x3, double y1, double y2, double y3,
double z1, double z2, double z3, double &A, double &B, double &C, double &D);
/**
* @brief Calculate the coefficients of a 3D plane defined by two points on a sphercial surface and the origin.
* The plane's equation is given as Ax + By + Cz + D = 0
*
* @param p1 point 1 on the spherical surface.
* @param p2 point 2 on the spherical surface.
* @param A coefficient A
* @param B coefficient B
* @param C coefficient C
* @param D coefficient D
*/
void get_plane_coeff(const point3ds &p1, const point3ds &p2, double &A, double &B, double &C, double &D);
/**
* @brief 线
*
* @param[in] face_p
* @param[in] face_nor 线
* @param[in] line_p 线
* @param[in] line_nor 线
*
* @return
*/
point3dc line_on_plane(const point3dc &face_p, const point3dc &face_nor,
const point3dc &line_p, const point3dc &line_nor);
/**
2024-11-06 16:50:15 +08:00
* @brief
2024-09-10 15:45:07 +08:00
*
2024-11-06 16:50:15 +08:00
* @param[in] v1
* @param[in] v2
* @param[in] arc ()
2024-09-10 15:45:07 +08:00
*
* @return
*/
2024-11-06 16:50:15 +08:00
point3ds track_sphere_arc(const point3ds &v1, const point3ds &v2, double arc);
2024-09-10 15:45:07 +08:00
/**
* @brief
*
* @param[in] face_dot
* @param[in] face_nor
* @param[in] dot
*
* @return
*/
point3dc dot_on_plane(const point3dc &face_dot, const point3dc &face_nor, const point3dc &dot);
/**
* @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_dis(const point3dc &p, const point3dc &p1, const point3dc &p2,
const point3dc &p3, double d1, double d2, double d3);
/**
* @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_ang(const point3dc &p, const point3dc &p1, const point3dc &p2,
const point3dc &p3, double d1, double d2, double d3);
/**
* @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 point3dc &p, const point3dc &p1, const point3dc &p2,
const point3dc &p3, double d1, double d2, double d3);
/**
* @brief
*
* @param[in] p
* @param[in] p1 1
* @param[in] p2 2
* @param[in] p3 3
* @param[in] p4 4
* @param[in] d1 1
* @param[in] d2 2
* @param[in] d3 3
* @param[in] d4 4
*
* @return
*/
double tet_interp_dis(const point3dc &p, const point3dc &p1, const point3dc &p2,
const point3dc &p3, const point3dc &p4, double d1, double d2, double d3, double d4);
/**
* @brief
*
* @param[in] sp_ptr
* @param cp_ptr
*
* @return
*/
int sph2car(const point3ds *sp_ptr, point3dc *cp_ptr);
/**
* @brief
*
* @param[in] cp_ptr
* @param sp_ptr
*
* @return
*/
int car2sph(const point3dc *cp_ptr, point3ds *sp_ptr);
/**
* @brief
*
* @param lon
* @param lat
* @param r
* @param R
* @return point3dc
*/
point3dc ellip2car(double lon, double lat, double r, double R);
/**
* @brief 线 order_triangular_surface中调用
*
* @param[in] origin 线
* @param[in] direct 线
* @param[in] tri_facet
* @param[in] active_edge 3线
* @param[in] cutoff_limit 0
* @param[in] cross_loc
*
* @return
*/
bool crossed_tri_facet(const point3dc &origin, const point3dc &direct, const triangle &tri_facet,
const bool *active_edge, double cutoff_limit = 1e-10, point3dc *cross_loc = nullptr);
/**
* @brief t1与t2是否在点p1p2与p3构成的平面的同一侧
*
* @param p1
* @param p2
* @param p3
* @param t1
* @param t2
* @return true
* @return false
*/
bool same_side(const point3dc &p1, const point3dc &p2, const point3dc &p3, const point3dc &t1, const point3dc &t2);
/**
* @brief
*
*
*
* @param test_p
* @param p1
* @param p2
* @param p3
* @param p4
*
* @return
*/
bool node_in_tetrahedron(const point3dc &p1, const point3dc &p2,
const point3dc &p3, const point3dc &p4, const point3dc &test_p);
/**
* @brief
*
* @param poly_tri_ptr Pointer of the triangle array
*
* @return status of the function
*/
void order_triangular_surface(array<triangle> &poly_tri, double cutoff_limit = 1e-10);
/**
* @brief
*
* @param[in] ele
* @param out_face
* @param out_neigh_ptr
*
*/
void get_tetra_mesh_common_faces(const array<tetrahedron> &ele, array<triangle> &out_face,
array<tetrahedron*> *out_neigh_ptr = nullptr);
/**
* @brief
*
*/
size_t sort_node_number(const array<tetrahedron> &ele);
/**
* @brief
*
* @param[in] ele
* @param neigh_list
* @param node_nump
*/
void sort_node_neighbor(const array<tetrahedron> &ele, std::vector<std::vector<tetrahedron*> > &neigh_list, size_t *node_nump = nullptr);
/**
* @brief
*
* @param ele
* @param node_nump
*/
void sort_tet_neighbor(array<tetrahedron> &ele, size_t *node_nump = nullptr);
/**
* @brief 使
*
* @note 线
*
* @param[in] in_eles
* @param[in] nor 线
* @param[in] surf
* @param out_nodes
* @param out_eles
*/
void cut_triangular_mesh(const array<triangle> &in_eles, const point3dc &nor, const point3dc &surf,
array<vertex3dc> &out_nodes, array<triangle> &out_eles);
}
2025-02-06 21:17:24 +08:00
};
2024-09-10 15:45:07 +08:00
#endif // _GCTL_GEOMETRY3D_H