当前位置: 首页 > news >正文

triangle_area_calculators库发布

最近将在pip网站上发布triangle_area_calculators库(我编写的python第三方库)

triangle_area_calculators库用于计算不同类型及不同已知量的三角形面积

在triangle_area_calculators库中,有一个名为TriangleAreaCalculators的类

可以通过from triangle_area_calculators import TriangleAreaCalculators方式引用

 

 

import math


class TriangleAreaCalculators:
    HALF = 0.5

    @staticmethod
    def area_by_base_height(base, height):
        return TriangleAreaCalculators.HALF * base * height

    @staticmethod
    def area_by_heron(a, b, c):
        p = (a + b + c) / 2
        return math.sqrt(p * (p - a) * (p - b) * (p - c))

    @staticmethod
    def area_by_two_sides_angle(a, b, gamma_degrees):
        gamma_radians = math.radians(gamma_degrees)
        return TriangleAreaCalculators.HALF * a * b * math.sin(gamma_radians)

    @staticmethod
    def area_by_coordinates(x1, y1, x2, y2, x3, y3):
        return TriangleAreaCalculators.HALF * abs(x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2))

    @staticmethod
    def area_by_vectors(A_x, A_y, B_x, B_y):
        return TriangleAreaCalculators.HALF * abs(A_x * B_y - A_y * B_x)

    @staticmethod
    def area_of_right_triangle_by_two_legs(a, b):
        return TriangleAreaCalculators.HALF * a * b

    @staticmethod
    def area_of_right_triangle_by_hypotenuse_and_leg(c, a):
        theta_radians = math.acos(a / c)
        return TriangleAreaCalculators.HALF * a * c * math.sin(theta_radians)

    @staticmethod
    def area_of_equilateral_triangle(a):
        return (math.sqrt(3) / 4) * a ** 2

    @staticmethod
    def area_of_isosceles_triangle_by_base_angle(b, a, theta_degrees):
        theta_radians = math.radians(theta_degrees)
        return TriangleAreaCalculators.HALF * b * a * math.sin(theta_radians)

    @staticmethod
    def area_of_isosceles_triangle_by_height(b, h):
        return TriangleAreaCalculators.HALF * b * h

    @staticmethod
    def area_of_isosceles_right_triangle(a):
        return TriangleAreaCalculators.HALF * a ** 2

    @staticmethod
    def area_of_circumscribed_triangle(R, alpha_degrees):
        alpha_radians = math.radians(alpha_degrees)
        return TriangleAreaCalculators.HALF * R ** 2 * math.sin(alpha_radians)
        
'''
#使用示例
from triangle_area_calculators import TriangleAreaCalculators


# 示例1:使用底和高计算三角形面积
base = 5
height = 8
print("底为", base, "高为", height, "的三角形面积:", TriangleAreaCalculators.area_by_base_height(base, height))

# 示例2:使用海伦公式计算三角形面积(已知三边)
a = 3
b = 4
c = 5
print("三边分别为", a, b, c, "的三角形面积:", TriangleAreaCalculators.area_by_heron(a, b, c))

# 示例3:使用两边和夹角计算三角形面积(这里传入角度制角度)
a_side = 6
b_side = 8
angle_gamma_degrees = 60
print("两边分别为", a_side, b_side, "夹角为", angle_gamma_degrees, "度的三角形面积:", TriangleAreaCalculators.area_by_two_sides_angle(a_side, b_side, angle_gamma_degrees))

# 示例4:使用坐标法计算三角形面积
x1, y1 = 1, 1
x2, y2 = 3, 4
x3, y3 = 5, 2
print("坐标分别为(", x1, y1, "), (", x2, y2, "), (", x3, y3, ")的三角形面积:", TriangleAreaCalculators.area_by_coordinates(x1, y1, x2, y2, x3, y3))

# 示例5:使用向量法计算三角形面积
A_x, A_y = 2, 3
B_x, B_y = 5, 7
print("向量坐标分别为(", A_x, A_y, "), (", B_x, B_y, ")的三角形面积:", TriangleAreaCalculators.area_by_vectors(A_x, A_y, B_x, B_y))

# 示例6:计算直角三角形面积(已知两条直角边)
right_a = 3
right_b = 4
print("两条直角边分别为", right_a, b, "的直角三角形面积:", TriangleAreaCalculators.area_of_right_triangle_by_two_legs(right_a, right_b))

# 示例7:计算直角三角形面积(已知斜边和一条直角边)
right_c = 5
right_a = 3
print("斜边为", right_c, "一条直角边为", right_a, "的直角三角形面积:", TriangleAreaCalculators.area_of_right_triangle_by_hypotenuse_and_leg(right_c, right_a))

# 示例8:计算等边三角形面积
equilateral_a = 6
print("边长为", equilateral_a, "的等边三角形面积:", TriangleAreaCalculators.area_of_equilateral_triangle(equilateral_a))

# 示例9:计算等腰三角形面积(已知底边、等腰边和顶角,这里传入角度制角度)
isosceles_b = 4
isosceles_a = 5
isosceles_theta_degrees = 45
print("底边为", isosceles_b, "等腰边为", isosceles_a, "顶角为", isosceles_theta_degrees, "度的等腰三角形面积:", TriangleAreaCalculators.area_of_isosceles_triangle_by_base_angle(isosceles_b, isosceles_a, isosceles_theta_degrees))

# 示例10:计算等腰三角形面积(已知等腰边和底边上的高)
isosceles_a_side = 5
isosceles_height = 3
print("等腰边为", isosceles_a_side, "底边上的高为", isosceles_height, "的等腰三角形面积:", TriangleAreaCalculators.area_of_isosceles_triangle_by_height(isosceles_a_side, isosceles_height))

# 示例11:计算等腰直角三角形面积
isosceles_right_a = 4
print("边长为", isosceles_right_a, "的等腰直角三角形面积:", TriangleAreaCalculators.area_of_isosceles_right_triangle(isosceles_right_a))

# 示例12:计算圆内接三角形面积(这里传入角度制角度)
R_radius = 3
alpha_degrees = 90
print("圆半径为", R_radius, "中心角为", alpha_degrees, "度的圆内接三角形面积:", TriangleAreaCalculators.area_of_circumscribed_triangle(R_radius, alpha_degrees))
'''

 

 

代码链接🔗:

http://localhost:8888/tree


http://www.mrgr.cn/news/66521.html

相关文章:

  • Rust 图形界面开发——使用 GTK 创建跨平台 GUI
  • 新一代跟踪器StrongSORT: Make DeepSORT Great Again论文解析—让 DeepSORT 再次伟大
  • 获得淘宝app商品详情原数据 API 券后价获取API
  • 前端将网页转换为pdf并支持下载与上传
  • 单集群 100 节点!资源占用远小于 Grafana Mimir——GreptimeDB 海量数据写入性能报告
  • TypeError: can‘t multiply sequence by non-int of type ‘float‘
  • 进程信号——信号的保存
  • 聚划算!Transformer-LSTM、Transformer、CNN-LSTM、LSTM、CNN五模型多变量回归预测
  • 0.推荐序
  • 3.5 windows xp ReactOS EiAllocatePool()
  • [代码随想录打卡Day7] 454.四数相加II 383. 赎金信 15. 三数之和 18. 四数之和
  • GCC编译器的`-Wall`、`-Wextra`和`-pedantic`选项解读
  • Vue3-子传父
  • ORA-00020和ORA-00603报错处理
  • 【算法】递归+深搜:106.从中序与后序遍历序列构造二叉树(medium)
  • B2118 验证子串
  • Swift 开发教程系列 - 第5章:集合类型
  • oracle数据检查方法
  • 多client向同一个pushgateway推送指标被覆盖问题
  • 解密抖音推荐算法:个性化内容背后的技术奥秘
  • 【MongoDB】MongoDB的聚合(Aggregate、Map Reduce)与管道(Pipline) 及索引详解(附详细案例)
  • 一篇文章速通Java开发Stream流(流水线开发附斗地主小游戏综合案例)
  • 一文快速预览经典深度学习模型(一)——CNN、RNN、LSTM、Transformer、ViT
  • Vue:计算属性
  • JavaScript 变量作用域与函数调用机制:var 示例详解
  • SEO