WPF 使用PathGeometry画时针和分针
来源:互联网 发布:吓人软件下载 编辑:程序博客网 时间:2024/05/03 17:10
// 将角度转为弧度 private double TransOrt2Radian(double fOrt) { double fPAI = 3.1415926535; double fTmp = fOrt + 270; if (fTmp > 360.0) fTmp -= 360.0; return (fTmp * fPAI) / (float)180.0; } private Point GetPointInCircle(double dCtrx, double dCtry, double dOrt, double dRadius) { Point pnt1 = new Point(0, 0); double dOrt1 = dOrt; if (dOrt > 360.0) dOrt -= 360.0; pnt1.X = dCtrx + dRadius * (float)Math.Cos(TransOrt2Radian(dOrt1)); pnt1.Y = dCtry + dRadius * (float)Math.Sin(TransOrt2Radian(dOrt1)); return pnt1; } // 根据提供的点获取一个封闭区域 private PathFigure GetLineFigure(Point pt1, Point []pts) { PathFigure pgtmp = new PathFigure(); pgtmp.StartPoint = pt1; PathSegmentCollection psc = new PathSegmentCollection(); for (int i = 0; i < pts.Count(); i++) { Point pnt = pts[i]; LineSegment lg = new LineSegment(); lg.Point = pnt; psc.Add(lg); } pgtmp.Segments = psc; pgtmp.IsClosed = true; pgtmp.IsFilled = true; return pgtmp; } // 根据半径和中心点获取指针区域 private PathFigure GetTimePointer(double dCtrx, double dCtry, double dRadius1, double dRadius2, double dRadius, double dOrt) { // 计算区域的四个点 Point pnt1 = GetPointInCircle(dCtrx, dCtry, dOrt + 180, dRadius1); Point pnt2 = GetPointInCircle(dCtrx, dCtry, dOrt + 70, dRadius2); Point pnt3 = GetPointInCircle(dCtrx, dCtry, dOrt - 70, dRadius2); Point pnt4 = GetPointInCircle(dCtrx, dCtry, dOrt, dRadius); PathFigure pgtmp = GetLineFigure(pnt1, new Point[3] { pnt2, pnt4, pnt3 }); return pgtmp; }
private void DrawTimePointer(DrawingContext dc) { if (ActualWidth < 30) return; double dCtrx = ActualWidth / 2; double dCtry = ActualHeight / 2; // 时针长度 double dHourRadius = ActualWidth * 7 / 20; double dHourRadius1 = ActualWidth * 3 / 40; double dHourRadius2 = ActualWidth / 20; // 时针角度 double dOrt = 90.0; // 分针长度 double dMinRadius = ActualWidth * 2 / 5; double dMinRadius1 = ActualWidth *3 / 40; double dMinRadius2 = dMinRadius1 / 2; // 分针角度 double dMinOrt = 21; // 计算区域 PathGeometry pg = new PathGeometry(); PathFigure pgtmp = GetTimePointer(dCtrx, dCtry, dHourRadius1, dHourRadius2, dHourRadius, dOrt); pg.Figures.Add(pgtmp); pg.Freeze(); dc.DrawGeometry(Brushes.Blue, new Pen(Brushes.Blue, 1.0), pg); PathGeometry pg2 = new PathGeometry(); PathFigure pgtmp2 = GetTimePointer(dCtrx, dCtry, dMinRadius1, dMinRadius2, dMinRadius, dMinOrt); pg2.Figures.Add(pgtmp2); pg2.Freeze(); dc.DrawGeometry(Brushes.Yellow, new Pen(Brushes.Green, 1.0), pg2); }
效果如图:
0 0
- WPF 使用PathGeometry画时针和分针
- 时针和分针交换
- 时针旋转一周,时针和分针重合次数。
- 时针,分针和秒针的重合问题
- hdu2076(时针和分针的夹角)
- 时针和分针多久重合一次
- 时针和分针夹角的问题
- HDU 2076 时针和分针夹角多大
- 时针分针重合
- 时针分针重合问题
- 时针分针重合问题
- 求任意时间之时针和分针间的角度
- 一天中时针和分针会相遇多少次?
- 算法:每过多长时间时针和分针相遇一次
- 时针、分针和秒针是群快乐的好伙伴
- 一天内时针和分针重叠的次数
- 时针分针重合问题与时针、分针、秒针重合问题
- hdu 1006 时针/分针/秒针
- HDU--2586--How far away ?【LCA】
- flume安装配置手册
- 解决Debian-7.6下eclipse-4.4崩溃问题
- 刚刚开始对协同化办公的认识
- hadoop中HDFS读写机制解析
- WPF 使用PathGeometry画时针和分针
- HDU 1063/POJ 1001-Exponentiation(大数类)
- Raw Socket
- EM 算法 的简单理解
- 【二分匹配】 HDU 2389 Rain on your Parade HK算法
- 每周精选编程技术文章与资源_9月8日至9月14日
- Implement strStr() [leetcode] BM算法和KMP算法
- 机器学习_最优化算法_梯度下降
- 查找字符流中第一个出现的不重复字符