公式为:

cotC=a2+b2−c24A

\cot C = \frac{a^2 + b^2 - c^2}{4A}

证明
根据余弦定理

cosC=a2+b2−c22ab\cos C = \frac{a^2 + b^2 - c^2}{2ab}

根据面积公式
A=12absinCA = \frac{1}{2}ab \sin C
所以
sinC=2Aab\sin C = \frac{2A}{ab}

所以cotC=cosCsinC=a2+b2−c22ab⋅ab2A=a2+b2−c24A\cot C =\frac{\cos C}{\sin C} = \frac{a^2 + b^2 - c^2}{2ab} \cdot \frac{ab}{2A} = \frac{a^2 + b^2 - c^2}{4A}

alec jacobson 代码:

function C = cotangent(V,F,varargin)% COTANGENT compute the cotangents of each angle in mesh (V,F), more details% can be found in Section 1.1 of "Algorithms and Interfaces for Real-Time% Deformation of 2D and 3D shapes" [Jacobson 2013]% % C = cotangent(V,F)% C = cotangent(V,F,'ParameterName',parameter_value,...)%% Known bugs:%   This seems to return 0.5*C and for tets already multiplies by%   edge-lengths%% Inputs:%   V  #V by dim list of rest domain positions%   F  #F by {3|4} list of {triangle|tetrahedra} indices into V%   Optional (3-manifolds only):%     'SideLengths' followed by #F by 3 list of edge lengths corresponding%       to: 23 31 12. In this case V is ignored.%       or%       followed by #T by 6 list of tet edges lengths:%       41 42 43 23 31 12%     'FaceAreas' followed by #T by 4 list of tet face areas% Outputs:%   C  #F by {3|6} list of cotangents corresponding%     angles for triangles, columns correspond to edges 23,31,12%     dihedral angles *times opposite edge length* over 6 for tets, %       WRONG: columns correspond to edges 23,31,12,41,42,43 %       RIGHT: columns correspond to *faces* 23,31,12,41,42,43%% See also: cotmatrix%% Copyright 2013, Alec Jacobson (jacobson@inf.ethz.ch)%switch size(F,2)case 3% default valuesl = [];% Map of parameter names to variable namesparams_to_variables = containers.Map( ...{'SideLengths'}, {'l'});v = 1;while v <= numel(varargin)param_name = varargin{v};if isKey(params_to_variables,param_name)assert(v+1<=numel(varargin));v = v+1;% Trick: use feval on anonymous function to use assignin to this workspace feval(@()assignin('caller',params_to_variables(param_name),varargin{v}));elseerror('Unsupported parameter: %s',varargin{v});endv=v+1;endassert(numel(varargin) == 0);% trianglesif isempty(l)% edge lengths numbered same as opposite verticesl = [ ...sqrt(sum((V(F(:,2),:)-V(F(:,3),:)).^2,2)) ...sqrt(sum((V(F(:,3),:)-V(F(:,1),:)).^2,2)) ...sqrt(sum((V(F(:,1),:)-V(F(:,2),:)).^2,2)) ...];endi1 = F(:,1); i2 = F(:,2); i3 = F(:,3);l1 = l(:,1); l2 = l(:,2); l3 = l(:,3);% semiperimeterss = (l1 + l2 + l3)*0.5;% Heron's formula for areadblA = 2*sqrt( s.*(s-l1).*(s-l2).*(s-l3));% cotangents and diagonal entries for element matrices% correctly divided by 4 (alec 2010)C = [ ...(l2.^2 + l3.^2 -l1.^2)./dblA/4 ...(l1.^2 + l3.^2 -l2.^2)./dblA/4 ...(l1.^2 + l2.^2 -l3.^2)./dblA/4 ...];case 4% Dealing with tetsT = F;l = [];s = [];v = 1;while v <= numel(varargin)switch varargin{v}case 'SideLengths'assert((v+1)<=numel(varargin));v = v+1;l = varargin{v};case 'FaceAreas'assert((v+1)<=numel(varargin));v = v+1;s = varargin{v};otherwiseerror(['Unsupported parameter: ' varargin{v}]);endv = v+1;endif isempty(l)% lengths of edges opposite *face* pairs: 23 31 12 41 42 43l = [ ...sqrt(sum((V(T(:,4),:)-V(T(:,1),:)).^2,2)) ...sqrt(sum((V(T(:,4),:)-V(T(:,2),:)).^2,2)) ...sqrt(sum((V(T(:,4),:)-V(T(:,3),:)).^2,2)) ...sqrt(sum((V(T(:,2),:)-V(T(:,3),:)).^2,2)) ...sqrt(sum((V(T(:,3),:)-V(T(:,1),:)).^2,2)) ...sqrt(sum((V(T(:,1),:)-V(T(:,2),:)).^2,2)) ...];end% (unsigned) face Areas (opposite vertices: 1 2 3 4)if isempty(s)s = 0.5*[ ...doublearea_intrinsic(l(:,[2 3 4])) ...doublearea_intrinsic(l(:,[1 3 5])) ...doublearea_intrinsic(l(:,[1 2 6])) ...doublearea_intrinsic(l(:,[4 5 6]))];end[~,cos_theta] = dihedral_angles([],[],'SideLengths',l,'FaceAreas',s);% volumevol = volume_intrinsic(l);%% Law of cosines%% http://math.stackexchange.com/a/49340/35376%H_sqr = (1/16) * ...%  (4*l(:,[4 5 6 1 2 3]).^2.* l(:,[1 2 3 4 5 6]).^2 - ...%  ((l(:, [2 3 4 5 6 1]).^2 + l(:,[5 6 1 2 3 4]).^2) - ...%  (l(:, [3 4 5 6 1 2]).^2 + l(:,[6 1 2 3 4 5]).^2)).^2);%cos_theta= (H_sqr - s(:,[2 3 1 4 4 4]).^2 - ...%                    s(:,[3 1 2 1 2 3]).^2)./ ...%                (-2*s(:,[2 3 1 4 4 4]).* ...%                    s(:,[3 1 2 1 2 3]));%% To retrieve dihedral angles stop here...%theta = acos(cos_theta);%theta/pi*180% Law of sines% http://mathworld.wolfram.com/Tetrahedron.html%sin_theta = bsxfun(@rdivide,vol,(2./(3*l)) .* s(:,[1 2 3 2 3 1]) .* s(:,[4 4 4 3 1 2]));sin_theta = bsxfun(@rdivide,vol,(2./(3*l)) .* s(:,[2 3 1 4 4 4]) .* s(:,[3 1 2 1 2 3]));%% Using sin for dihedral angles gets into trouble with signs%theta = asin(sin_theta);%theta/pi*180% http://arxiv.org/pdf/1208.0354.pdf Page 18C = 1/6 * l .* cos_theta ./ sin_theta;%% One should probably never use acot to retrieve signed angles%theta = acot(C);%theta/pi*180otherwiseerror('Unsupported simplex type');endend

如何算三角形的cotangent相关推荐

  1. C语言输入三角形三条边边长 算三角形面积

    C语言输入三角形三条边边长 算三角形面积 方法:S=sqrt(p*(p-a)(p-b)(p-c)); //海伦公式 代码: #include<stdio.h> #include<ma ...

  2. python求三角形面积步骤_python算三角形面积

    展开全部 代码如下: #!/usr/bin/python3 # -*- coding:utf-8 -*- """ @author:yaqon @file :shanjia ...

  3. python算三角形面积怎么样保留两位小数_通过坐标计算三角形面积

    描述 平面上有一个三角形,它的三个顶点坐标分别为(x1, y1), (x2, y2), (x3, y3),那么请问这个三角形的面积是多少. 输入 输入仅一行,包括6个单精度浮点数,分别对应x1, y1 ...

  4. C语言算三角形外心坐标,【c语言】三角形外心坐标

    新学期第一个算法大作业就好坑爹... 要计算三角形外接圆...做模板用吧 # include # include double X1,Y1,X2,Y2,X3,Y3,x4,y4,length1,leng ...

  5. C语言算三角形外心坐标,三角形外心坐标公式(含C语言代码).pdf

    三角形外心坐标公式(含C语言代码).pdf (1页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 11.90 积分 =2 − + − − −2 − + − ...

  6. 009--python--计算三角形的周长和面积

    """ 输入三条边长,如果能构成三角形计算周长和面积. 三角形的组成条件:任意一边大于两边之差,任意一边小于其他两边之和. """ a=fl ...

  7. C语言三个点坐标算三角形面积,c语言计算三角形面积代码

    //面积公式s = (a+b+c) / 2   area = sqrt(s * (s - a) * (s - b) * (s - c)); //小作业 求三角形的面积 int check(double ...

  8. c语言算三角形面积,c语言计算三角形面积代码

    //面积公式s = (a+b+c) / 2   area = sqrt(s * (s - a) * (s - b) * (s - c)); //小作业 求三角形的面积 int check(double ...

  9. java中算三角形面积_java中用类求三角形面积

    展开全部 海伦公式 p=(a+b+c)/2 看了一眼代码,写了一下你看一下 public class area { double area(double xx1, double yy1, double ...

最新文章

  1. 最新手机号段归属地数据库(2017年4月16日版)免费下载
  2. 【机器学习入门】(1) K近邻算法:原理、实例应用(红酒分类预测)附python完整代码及数据集
  3. 使用STVP解除STM32读保护
  4. 以太坊智能合约开发第七篇:智能合约与网页交互
  5. 王志成/王之泰《面向对象程序设计(java)》第十一周学习总结
  6. gcc / -L 和 -Wl,-rpath 区别
  7. Tensorflow(一) 基础命令
  8. C#操作sql通用类 SQLHelper
  9. 网络IO之阻塞、非阻塞、同步、异步总结
  10. 【JAVA基础】HashSet、LinkedHashSet、TreeSet使用区别
  11. char 数组和 int 之间转化
  12. paip.undefined reference to MainWindow::xxx from moc_mainwindow.cpp错误解决
  13. 停止kibana服务
  14. python中code函数是干嘛的_[Code] Python简单小知识
  15. 微信每日早安推送,自定义推送名称,企业号推送非订阅号测试号,python源码,无需第三方多个网站注册、无第三方接口,无基础快速上不了手
  16. java中怎么创建表格_Java中的表格怎么利用表格模型进行创建
  17. mysql中Tinyint(1)和Tinyint(4)的区别
  18. liunx下查看tomcat占用的端口号
  19. 单元测试技巧之PowerMock
  20. 骚操作!程序员埋下每隔几年就触发的逻辑炸弹 | 每日趣闻

热门文章

  1. Qt捕捉窗口关闭事件
  2. 拔染印花几点注意事项
  3. 机器视觉:锡膏印刷质量3D检测光学系统
  4. Halcon 学习总结——制作标定板(函数gen_caltab)
  5. 2017 年十大网页设计趋势
  6. Servlet规范总结
  7. getconf 取系统配制 --CPU
  8. ThinkPHP的介绍和安装
  9. 【VMCloud云平台】SCOM配置(额外篇)-应用可用性150点实时性测试
  10. JavaScript加密库Crypto-JS的使用