PPT里确定三角形外心,即三条边的垂直平分线的交点的VBA代码 
时间: 2023-02-28 08:31:59 浏览: 34
要确定三角形外心,可以使用如下VBA代码:Sub FindGravityCenterOfTriangle()
Dim aX As Single, aY As Single, bX As Single, bY As Single, cX As Single, cY As Single
Dim centerX As Single, centerY As SingleaX = InputBox("请输入第一个点X坐标")
aY = InputBox("请输入第一个点Y坐标")
bX = InputBox("请输入第二个点X坐标")
bY = InputBox("请输入第二个点Y坐标")
cX = InputBox("请输入第三个点X坐标")
cY = InputBox("请输入第三个点Y坐标")centerX = (aX + bX + cX) / 3
centerY = (aY + bY + cY) / 3MsgBox "三角形外心的坐标是:(" & centerX & "," & centerY & ")"End Sub
相关问题
基于c++ 三维 三角形外心球阀
三维空间中的三角形外心球阀可以通过以下步骤来实现:
1. 计算三角形的外接圆圆心
首先,需要计算出三角形的外接圆圆心,这可以通过以下公式来实现:
```
// 计算三角形外接圆圆心
Vector3D circumcenter(const Triangle& tri) {
Vector3D A = tri.p[0];
Vector3D B = tri.p[1];
Vector3D C = tri.p[2];
Vector3D AB = (B - A) * 0.5;
Vector3D AC = (C - A) * 0.5;
Vector3D ABxAC = cross(AB, AC);
Vector3D v = cross(ABxAC, AB);
Vector3D w = cross(AC, ABxAC);
return A + (v * (AC.magnitude_squared()) + w * (AB.magnitude_squared())) / (2.0 * ABxAC.magnitude_squared());
}
```
其中,`Triangle` 表示三角形,`Vector3D` 表示三维向量,`cross` 函数表示向量的叉积运算,`magnitude_squared` 函数表示向量长度的平方。
2. 计算外接圆半径
接下来,需要计算出外接圆的半径,这可以通过以下公式来实现:
```
// 计算三角形外接圆半径
double circumradius(const Triangle& tri) {
Vector3D A = tri.p[0];
Vector3D B = tri.p[1];
Vector3D C = tri.p[2];
Vector3D AB = B - A;
Vector3D AC = C - A;
double AB_length_squared = AB.magnitude_squared();
double AC_length_squared = AC.magnitude_squared();
double ABxAC_length = cross(AB, AC).magnitude();
return AB_length_squared * AC_length_squared * (AB - AC).magnitude() / (4.0 * ABxAC_length * ABxAC_length);
}
```
3. 构造外接圆球阀
最后,可以通过外接圆圆心和半径来构造出外接圆球阀,这可以通过以下代码来实现:
```
// 构造三角形外接圆球阀
Sphere circumcircle(const Triangle& tri) {
Vector3D center = circumcenter(tri);
double radius = circumradius(tri);
return Sphere(center, radius);
}
```
其中,`Sphere` 表示球阀,构造函数接受圆心和半径作为参数。
这样就可以实现基于 C++ 的三维三角形外心球阀计算了。
已知三角形三点坐标求外心坐标,用python编写函数
以下是用python编写的求三角形外心坐标的函数:
```python
import math
def outcenter(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float) -> tuple:
'''
三角形外心坐标计算函数
:param x1: 第一个点的横坐标
:param y1: 第一个点的纵坐标
:param x2: 第二个点的横坐标
:param y2: 第二个点的纵坐标
:param x3: 第三个点的横坐标
:param y3: 第三个点的纵坐标
:return: 外心坐标
'''
a = math.sqrt((x2-x1)**2+(y2-y1)**2)
b = math.sqrt((x3-x2)**2+(y3-y2)**2)
c = math.sqrt((x1-x3)**2+(y1-y3)**2)
p = a + b + c
s = math.sqrt(p * (p - 2*a) * (p - 2*b) * (p - 2*c))
A = (x1 + x2 + x3) / 3
B = (y1 + y2 + y3) / 3
Ox = (a**2 * (b**2 + c**2 - a**2) * x1 + b**2 * (c**2 + a**2 - b**2) * x2 + c**2 * (a**2 + b**2 - c**2) * x3) / (16 * s**2)
Oy = (a**2 * (b**2 + c**2 - a**2) * y1 + b**2 * (c**2 + a**2 - b**2) * y2 + c**2 * (a**2 + b**2 - c**2) * y3) / (16 * s**2)
return Ox, Oy
```
该函数输入三个点的横纵坐标,返回三角形外心的坐标。使用方法示例:
```python
>>> outcenter(0, 0, 1, 0, 0, 1)
(0.5, 0.5)
```
相关推荐




