SiamCafe.net Blog
Technology
Multus CNI Internal Developer Platform | SiamCafe Blog
2025-12-13· อ. บอม — SiamCafe.net· 9,153 คำ

?????????????????????????????????????????????????????????????????????????????????????????????

????????????????????????????????? (Median) ??????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????????? 3 ????????????????????????????????? ?????????????????????????????????????????????????????? 3 ????????????????????????????????????????????????????????????????????????????????????????????? Centroid (????????????????????????????????????) ???????????????????????????????????????????????????????????????????????????????????????????????????

???????????????????????????????????????????????????????????????????????????????????? ????????? Centroid ????????????????????????????????????????????????????????????????????????????????????????????????????????? 2:1 ?????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????? Centroid ???????????? 2 ?????? 3 ????????????????????????????????????????????????????????????????????????????????????

????????????????????????????????????????????? (Midline Theorem ???????????? Midsegment Theorem) ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????? ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

??????????????????????????????????????????????????????

?????????????????????????????????????????????????????????????????? (Apollonius's Theorem)

# === Median Length Formula (Apollonius's Theorem) ===
#
# ???????????????????????????????????????????????? ABC ??????????????????????????? a, b, c
# ????????? a = BC, b = AC, c = AB
#
# ??????????????????????????????????????????????????? A ???????????????????????????????????????????????? BC (???????????????????????? m_a):
#   m_a = (1/2) * sqrt(2b^2 + 2c^2 - a^2)
#
# ??????????????????????????????????????????????????? B ???????????????????????????????????????????????? AC (m_b):
#   m_b = (1/2) * sqrt(2a^2 + 2c^2 - b^2)
#
# ??????????????????????????????????????????????????? C ???????????????????????????????????????????????? AB (m_c):
#   m_c = (1/2) * sqrt(2a^2 + 2b^2 - c^2)
#
# === Proof using Stewart's Theorem ===
# Stewart's Theorem: b^2*m + c^2*n - a*m*n = a*d^2
# ?????????????????? cevian d ????????????????????????????????? a ???????????? m ????????? n
#
# ?????????????????? median: m = n = a/2
# b^2*(a/2) + c^2*(a/2) - a*(a/2)*(a/2) = a*m_a^2
# (a/2)(b^2 + c^2 - a^2/2) = a*m_a^2
# (b^2 + c^2 - a^2/2) / 2 = m_a^2
# m_a^2 = (2b^2 + 2c^2 - a^2) / 4
# m_a = (1/2) * sqrt(2b^2 + 2c^2 - a^2)  ???
#
# === Midsegment Theorem ===
# ???????????????????????? DE (D ????????????????????????????????? AB, E ????????????????????????????????? AC)
# ????????????: DE // BC ????????? DE = BC / 2
#
# Proof:
# ????????? A = (x1, y1), B = (x2, y2), C = (x3, y3)
# D = ((x1+x2)/2, (y1+y2)/2)  (????????????????????????????????? AB)
# E = ((x1+x3)/2, (y1+y3)/2)  (????????????????????????????????? AC)
#
# Vector DE = E - D = ((x3-x2)/2, (y3-y2)/2) = (1/2) * Vector BC
# ????????????????????? DE // BC ????????? |DE| = |BC|/2  ???

# === Centroid Theorem ===
# Centroid G = ((x1+x2+x3)/3, (y1+y2+y3)/3)
# G ???????????? median ????????????????????????????????? 2:1 ???????????????????????????
#
# Proof:
# Median ????????? A ?????? M (????????????????????????????????? BC)
# M = ((x2+x3)/2, (y2+y3)/2)
# ?????????????????????????????? AM ????????????????????????????????? 2:1:
# P = A + (2/3)(M - A)
#   = (x1, y1) + (2/3)(((x2+x3)/2 - x1), ((y2+y3)/2 - y1))
#   = ((x1+x2+x3)/3, (y1+y2+y3)/3)
#   = G  ???

echo "Theorems proven"

????????????????????????????????? Coordinate Geometry

???????????????????????????????????????????????????????????????????????????????????????????????????????????????

#!/usr/bin/env python3
# median_proof.py ??? Coordinate Geometry Proof
import math
import json
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("geometry")

class Triangle:
    def __init__(self, A, B, C):
        self.A = A  # (x, y)
        self.B = B
        self.C = C
    
    def side_lengths(self):
        a = math.dist(self.B, self.C)  # BC
        b = math.dist(self.A, self.C)  # AC
        c = math.dist(self.A, self.B)  # AB
        return {"a": round(a, 4), "b": round(b, 4), "c": round(c, 4)}
    
    def midpoint(self, P, Q):
        return ((P[0] + Q[0]) / 2, (P[1] + Q[1]) / 2)
    
    def median_from_A(self):
        M = self.midpoint(self.B, self.C)
        length = math.dist(self.A, M)
        return {"endpoint": M, "length": round(length, 4)}
    
    def median_from_B(self):
        M = self.midpoint(self.A, self.C)
        length = math.dist(self.B, M)
        return {"endpoint": M, "length": round(length, 4)}
    
    def median_from_C(self):
        M = self.midpoint(self.A, self.B)
        length = math.dist(self.C, M)
        return {"endpoint": M, "length": round(length, 4)}
    
    def median_by_formula(self):
        """Apollonius's theorem"""
        sides = self.side_lengths()
        a, b, c = sides["a"], sides["b"], sides["c"]
        
        m_a = 0.5 * math.sqrt(2*b**2 + 2*c**2 - a**2)
        m_b = 0.5 * math.sqrt(2*a**2 + 2*c**2 - b**2)
        m_c = 0.5 * math.sqrt(2*a**2 + 2*b**2 - c**2)
        
        return {
            "m_a": round(m_a, 4),
            "m_b": round(m_b, 4),
            "m_c": round(m_c, 4),
        }
    
    def centroid(self):
        gx = (self.A[0] + self.B[0] + self.C[0]) / 3
        gy = (self.A[1] + self.B[1] + self.C[1]) / 3
        return (round(gx, 4), round(gy, 4))
    
    def verify_centroid_ratio(self):
        """Verify centroid divides medians in 2:1 ratio"""
        G = self.centroid()
        
        # Median from A
        M_a = self.midpoint(self.B, self.C)
        AG = math.dist(self.A, G)
        GM = math.dist(G, M_a)
        ratio_a = round(AG / GM, 4) if GM > 0 else None
        
        # Median from B
        M_b = self.midpoint(self.A, self.C)
        BG = math.dist(self.B, G)
        GM_b = math.dist(G, M_b)
        ratio_b = round(BG / GM_b, 4) if GM_b > 0 else None
        
        return {
            "centroid": G,
            "ratio_median_A": ratio_a,
            "ratio_median_B": ratio_b,
            "all_ratios_2_to_1": all(abs(r - 2.0) < 0.001 for r in [ratio_a, ratio_b] if r),
        }
    
    def midsegment_theorem(self):
        """Verify midsegment is parallel and half length"""
        D = self.midpoint(self.A, self.B)
        E = self.midpoint(self.A, self.C)
        
        DE_length = math.dist(D, E)
        BC_length = math.dist(self.B, self.C)
        
        # Check parallel: vectors are proportional
        DE_vec = (E[0] - D[0], E[1] - D[1])
        BC_vec = (self.C[0] - self.B[0], self.C[1] - self.B[1])
        
        is_parallel = abs(DE_vec[0] * BC_vec[1] - DE_vec[1] * BC_vec[0]) < 0.0001
        is_half = abs(DE_length - BC_length / 2) < 0.0001
        
        return {
            "D_midpoint_AB": D,
            "E_midpoint_AC": E,
            "DE_length": round(DE_length, 4),
            "BC_length": round(BC_length, 4),
            "DE_parallel_BC": is_parallel,
            "DE_equals_half_BC": is_half,
        }

# Test with triangle A(0,0), B(6,0), C(2,8)
tri = Triangle((0, 0), (6, 0), (2, 8))
print("Sides:", json.dumps(tri.side_lengths()))
print("Medians (coordinate):", json.dumps({
    "from_A": tri.median_from_A()["length"],
    "from_B": tri.median_from_B()["length"],
    "from_C": tri.median_from_C()["length"],
}))
print("Medians (formula):", json.dumps(tri.median_by_formula()))
print("Centroid:", json.dumps(tri.verify_centroid_ratio()))
print("Midsegment:", json.dumps(tri.midsegment_theorem()))

??????????????????????????? Python

??????????????????????????????????????????????????????????????????????????????

#!/usr/bin/env python3
# triangle_calculator.py ??? Triangle Median Calculator
import math
import json
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("calculator")

class TriangleCalculator:
    def __init__(self):
        self.results = {}
    
    def from_vertices(self, A, B, C):
        """Calculate all properties from vertex coordinates"""
        a = math.dist(B, C)
        b = math.dist(A, C)
        c = math.dist(A, B)
        
        # Semi-perimeter
        s = (a + b + c) / 2
        
        # Area (Heron's formula)
        area = math.sqrt(s * (s - a) * (s - b) * (s - c))
        
        # Medians
        m_a = 0.5 * math.sqrt(2*b**2 + 2*c**2 - a**2)
        m_b = 0.5 * math.sqrt(2*a**2 + 2*c**2 - b**2)
        m_c = 0.5 * math.sqrt(2*a**2 + 2*b**2 - c**2)
        
        # Centroid
        G = ((A[0]+B[0]+C[0])/3, (A[1]+B[1]+C[1])/3)
        
        # Circumcenter (????????????????????????????????????????????????????????????????????????)
        D_val = 2 * (A[0]*(B[1]-C[1]) + B[0]*(C[1]-A[1]) + C[0]*(A[1]-B[1]))
        if abs(D_val) > 1e-10:
            ux = ((A[0]**2+A[1]**2)*(B[1]-C[1]) + (B[0]**2+B[1]**2)*(C[1]-A[1]) + (C[0]**2+C[1]**2)*(A[1]-B[1])) / D_val
            uy = ((A[0]**2+A[1]**2)*(C[0]-B[0]) + (B[0]**2+B[1]**2)*(A[0]-C[0]) + (C[0]**2+C[1]**2)*(B[0]-A[0])) / D_val
            circumcenter = (round(ux, 4), round(uy, 4))
            circumradius = round(math.dist(circumcenter, A), 4)
        else:
            circumcenter = None
            circumradius = None
        
        # Incircle (??????????????????????????????)
        inradius = round(area / s, 4)
        ix = (a*A[0] + b*B[0] + c*C[0]) / (a + b + c)
        iy = (a*A[1] + b*B[1] + c*C[1]) / (a + b + c)
        incenter = (round(ix, 4), round(iy, 4))
        
        return {
            "vertices": {"A": A, "B": B, "C": C},
            "sides": {"a_BC": round(a, 4), "b_AC": round(b, 4), "c_AB": round(c, 4)},
            "perimeter": round(a + b + c, 4),
            "area": round(area, 4),
            "medians": {"m_a": round(m_a, 4), "m_b": round(m_b, 4), "m_c": round(m_c, 4)},
            "centroid": (round(G[0], 4), round(G[1], 4)),
            "circumcenter": circumcenter,
            "circumradius": circumradius,
            "incenter": incenter,
            "inradius": inradius,
            "angles": self._angles(a, b, c),
            "type": self._classify(a, b, c),
        }
    
    def _angles(self, a, b, c):
        A_angle = math.degrees(math.acos((b**2 + c**2 - a**2) / (2*b*c)))
        B_angle = math.degrees(math.acos((a**2 + c**2 - b**2) / (2*a*c)))
        C_angle = 180 - A_angle - B_angle
        return {
            "A": round(A_angle, 2),
            "B": round(B_angle, 2),
            "C": round(C_angle, 2),
        }
    
    def _classify(self, a, b, c):
        sides = sorted([a, b, c])
        if abs(sides[0] - sides[2]) < 0.001:
            return "equilateral"
        elif abs(sides[0] - sides[1]) < 0.001 or abs(sides[1] - sides[2]) < 0.001:
            shape = "isosceles"
        else:
            shape = "scalene"
        
        if abs(sides[2]**2 - sides[0]**2 - sides[1]**2) < 0.001:
            return f"{shape} right"
        elif sides[2]**2 > sides[0]**2 + sides[1]**2:
            return f"{shape} obtuse"
        else:
            return f"{shape} acute"

calc = TriangleCalculator()

# Example 1: Right triangle
result = calc.from_vertices((0, 0), (3, 0), (0, 4))
print("Right Triangle:")
print(f"  Sides: {result['sides']}")
print(f"  Medians: {result['medians']}")
print(f"  Area: {result['area']}")
print(f"  Centroid: {result['centroid']}")
print(f"  Type: {result['type']}")

# Example 2: Equilateral triangle
h = math.sqrt(3) / 2 * 6
result2 = calc.from_vertices((0, 0), (6, 0), (3, h))
print(f"\nEquilateral Triangle:")
print(f"  Medians: {result2['medians']}")
print(f"  Centroid: {result2['centroid']}")
print(f"  Type: {result2['type']}")

????????????????????????????????????????????????????????????

??????????????????????????????????????????????????????????????????????????????

#!/usr/bin/env python3
# applications.py ??? Real-world Applications of Medians
import math
import json
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("applications")

class CentroidApplications:
    """Applications of triangle centroid in engineering"""
    
    def center_of_mass(self, vertices, mass_per_vertex=None):
        """Calculate center of mass of triangular plate"""
        if mass_per_vertex is None:
            # Uniform density: centroid = center of mass
            gx = sum(v[0] for v in vertices) / 3
            gy = sum(v[1] for v in vertices) / 3
            return {"center_of_mass": (round(gx, 4), round(gy, 4)), "type": "uniform"}
        else:
            total_mass = sum(mass_per_vertex)
            gx = sum(v[0] * m for v, m in zip(vertices, mass_per_vertex)) / total_mass
            gy = sum(v[1] * m for v, m in zip(vertices, mass_per_vertex)) / total_mass
            return {"center_of_mass": (round(gx, 4), round(gy, 4)), "type": "weighted"}
    
    def triangulation_centroid(self, points):
        """Find centroid of polygon using triangulation"""
        n = len(points)
        if n < 3:
            return None
        
        total_area = 0
        cx, cy = 0, 0
        
        for i in range(1, n - 1):
            A, B, C = points[0], points[i], points[i + 1]
            area = 0.5 * abs((B[0]-A[0])*(C[1]-A[1]) - (C[0]-A[0])*(B[1]-A[1]))
            tri_cx = (A[0] + B[0] + C[0]) / 3
            tri_cy = (A[1] + B[1] + C[1]) / 3
            cx += area * tri_cx
            cy += area * tri_cy
            total_area += area
        
        if total_area > 0:
            cx /= total_area
            cy /= total_area
        
        return {
            "centroid": (round(cx, 4), round(cy, 4)),
            "total_area": round(total_area, 4),
        }
    
    def structural_analysis(self):
        """Triangle medians in structural engineering"""
        return {
            "truss_analysis": {
                "description": "???????????????????????????????????????????????????????????????????????????????????????????????? truss member ????????????????????????????????? load distribution",
                "formula": "Load at centroid = Total distributed load",
            },
            "foundation_design": {
                "description": "Centroid ?????????????????????????????????????????? load ?????????????????????????????????????????????????????????????????????????????????",
                "formula": "Foundation center = Centroid of triangular footing",
            },
            "gis_mapping": {
                "description": "Triangulation ?????? GIS ???????????????????????? terrain model (TIN) ???????????????????????????????????????????????????????????????????????????????????????????????????????????? triangle",
                "method": "Delaunay Triangulation + Centroid calculation",
            },
            "computer_graphics": {
                "description": "Centroid ??????????????? mesh rendering, collision detection ????????? physics simulation",
                "method": "Barycentric coordinates relative to centroid",
            },
        }

app = CentroidApplications()

# Center of mass
vertices = [(0, 0), (6, 0), (3, 5)]
com = app.center_of_mass(vertices)
print("Center of Mass:", json.dumps(com))

# Weighted (different mass at each vertex)
com_weighted = app.center_of_mass(vertices, [1, 2, 3])
print("Weighted CoM:", json.dumps(com_weighted))

# Polygon centroid
polygon = [(0, 0), (4, 0), (5, 3), (2, 5), (0, 3)]
poly_c = app.triangulation_centroid(polygon)
print("Polygon Centroid:", json.dumps(poly_c))

# Structural applications
struct = app.structural_analysis()
for key, val in struct.items():
    print(f"\n{key}: {val['description']}")

????????????????????????????????????????????????????????????

????????????????????????????????????????????????????????????

# === Practice Problems ===

# Problem 1: ?????????????????????????????????????????????????????????????????????????????? A
# ?????????????????????????????? ABC ?????? A(1,2), B(5,2), C(3,8)
# Solution:
# a = BC = sqrt((5-3)^2 + (2-8)^2) = sqrt(4+36) = sqrt(40)
# b = AC = sqrt((1-3)^2 + (2-8)^2) = sqrt(4+36) = sqrt(40)
# c = AB = sqrt((1-5)^2 + (2-2)^2) = 4
# m_a = (1/2) * sqrt(2*40 + 2*16 - 40) = (1/2) * sqrt(72) = 3*sqrt(2) ??? 4.243

# Problem 2: ?????? Centroid
# ?????????????????????????????? PQR ?????? P(0,0), Q(12,0), R(6,9)
# G = ((0+12+6)/3, (0+0+9)/3) = (6, 3)
# ?????????????????????: ?????????????????????????????????????????? P ??????????????????????????????????????? QR
# M_qr = ((12+6)/2, (0+9)/2) = (9, 4.5)
# PG = sqrt(6^2 + 3^2) = sqrt(45)
# GM = sqrt((6-9)^2 + (3-4.5)^2) = sqrt(9+2.25) = sqrt(11.25)
# PG/GM = sqrt(45)/sqrt(11.25) = sqrt(4) = 2 ??? (??????????????????????????? 2:1)

# Problem 3: ?????????????????????????????????????????????
# ?????????????????????????????? ABC ?????? A(0,0), B(8,0), C(4,6)
# D = ????????????????????????????????? AB = (4, 0)
# E = ????????????????????????????????? AC = (2, 3)
# DE = sqrt((4-2)^2 + (0-3)^2) = sqrt(4+9) = sqrt(13)
# BC = sqrt((8-4)^2 + (0-6)^2) = sqrt(16+36) = sqrt(52) = 2*sqrt(13)
# DE = sqrt(13) = (1/2) * 2*sqrt(13) = BC/2 ???
# Vector DE = (2-4, 3-0) = (-2, 3)
# Vector BC = (4-8, 6-0) = (-4, 6) = 2*(-2, 3) = 2*DE
# ????????????????????? DE // BC ???

# Problem 4: ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
# ????????????????????????????????? 1 ?????????????????????????????????????????????????????????????????? 2 ?????????????????????????????????
# ????????????????????????????????? 3 ?????????????????????????????????????????????????????????????????? 6 ?????????????????????????????????
# ?????????????????????????????????????????????????????? = 1/6 ????????????????????????????????????????????????????????????????????????

# Problem 5: ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
# ???????????????????????????????????????????????????????????????????????????????????????????????? m_a, m_b, m_c
# ????????????????????? = (4/3) * sqrt(s_m(s_m-m_a)(s_m-m_b)(s_m-m_c))
# ????????? s_m = (m_a + m_b + m_c) / 2

echo "Practice problems complete"

FAQ ??????????????????????????????????????????

Q: ????????????????????????????????? ????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????????

A: ????????????????????????????????? (Median) ???????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? Centroid (????????????????????????????????????) ????????????????????? (Altitude) ??????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? Orthocenter ???????????????????????????????????????????????? (Angle Bisector) ?????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? Incenter (??????????????????????????????????????????????????????????????????) ???????????? 3 ??????????????????????????????????????????????????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????????????????????????????????????????????????

Q: ???????????? Centroid ?????????????????????????????????????????????????????????????????????????????? 2:1?

A: ??????????????? Centroid ????????????????????????????????????????????????????????????????????????????????????????????? 3 ?????????????????? G = ((x1+x2+x3)/3, (y1+y2+y3)/3) ?????????????????????????????????????????????????????????????????????????????? A ??????????????????????????????????????? M ????????? BC ????????? G ?????????????????? AM ????????? AG = 2/3 ????????? AM ????????? GM = 1/3 ????????? AM ????????????????????? AG:GM = 2:1 ???????????????????????????????????????????????????????????? vector ????????? G = A + (2/3)(M - A) ???????????? G = (1/3)(A + B + C)

Q: Midsegment Theorem ???????????????????????????????????????????????????????????????????

A: ????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? midsegment (????????? 2) ???????????????????????????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????? (midsegment ??????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????????? 1:2) ????????????????????????????????????????????????????????????????????????????????? bracing members ?????? truss ?????? computer graphics ????????? subdivision surfaces

Q: ??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

A: ????????????????????? Area = (4/3) * sqrt(s_m * (s_m - m_a) * (s_m - m_b) * (s_m - m_c)) ????????? s_m = (m_a + m_b + m_c) / 2 ??????????????????????????? Heron ?????????????????????????????????????????????????????????????????????????????? 4/3 ???????????????????????? ????????????????????????????????????????????????????????????????????? 3, 4, 5 s_m = 6 Area = (4/3)*sqrt(6*3*2*1) = (4/3)*sqrt(36) = (4/3)*6 = 8 ??????????????????????????????

Q: ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

A: ???????????????????????????????????????????????????????????? ????????????????????????????????????????????? 3 ?????????????????????????????????????????? ?????????????????????????????????????????????????????????????????????????????????????????????????????? ???????????????????????????????????????????????? ?????????????????????????????????????????????????????????????????? Centroid, Orthocenter, Circumcenter, Incenter ????????????????????????????????????????????? ?????????????????????????????? a ?????????????????????????????????????????????????????? = a*sqrt(3)/2 ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 30 ????????????

📖 บทความที่เกี่ยวข้อง

Multus CNI Cloud Native Designอ่านบทความ → Multus CNI Metric Collectionอ่านบทความ → Multus CNI SaaS Architectureอ่านบทความ → Multus CNI Pub Sub Architectureอ่านบทความ → WordPress WooCommerce Internal Developer Platformอ่านบทความ →

📚 ดูบทความทั้งหมด →