zoukankan      html  css  js  c++  java
  • 根据中心点、半径长度和角度画点

    直接上代码: 需要引用 Math 单元。

    procedure CenterRadiusPoint(const PX, PY: Integer; const Angle: Double;
      const Radius: Integer; var X, Y: Integer);
    var
      AngleHude: Double;
    begin
      AngleHude := Angle * PI / 180;  // 角度变成弧度
      X := Round(Radius * Cos(AngleHude)) + PX;
      Y := Round(Radius * Sin(AngleHude)) + PY;
    end;

    C#版:

            /// 根据中心点、半径、角度,求半径另一端的坐标。注意用的是笛卡尔坐标系  
            /// </summary>  
            /// <param name="center">中心点</param>  
            /// <param name="angle">半径角度</param>  
            /// <param name="radius">半径长度</param>  
            /// <returns>半径另一端的坐标</returns>  
            public static Point CenterRadiusPoint(Point center, double angle, double  radius)  
            {  
                Point p = new Point();  
                double angleHude = angle * Math.PI / 180;/*角度变成弧度*/  
                p.X = (int)(radius * Math.Cos(angleHude)) + center .X;  
                p.Y = (int)(radius * Math.Sin(angleHude)) + center .Y;  
                return p;  
            }    

    使用示例:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ExtCtrls;
    
    type
      TForm1 = class(TForm)
        Timer1: TTimer;
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure Timer1Timer(Sender: TObject);
      private
        { Private declarations }
        AX, AY: Integer;
        R: Integer;
      public
        { Public declarations }
        procedure Clear();
        procedure CenterRadiusPoint(const PX, PY: Integer; const Angle: Double;
          const Radius: Integer; var X, Y: Integer);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Math;
    
    procedure TForm1.CenterRadiusPoint(const PX, PY: Integer; const Angle: Double;
      const Radius: Integer; var X, Y: Integer);
    var
      AngleHude: Double;
    begin
      AngleHude := Angle * PI / 180;  // 角度变成弧度
      X := Round(Radius * Cos(AngleHude)) + PX;
      Y := Round(Radius * Sin(AngleHude)) + PY;
    end;
    
    procedure TForm1.Clear;
    begin
      Canvas.FillRect(Canvas.ClipRect);
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      AX := X;
      AY := Y;
      R := 0;
      Clear();
    end;
    
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
      I: Integer;
      X, Y: Integer;
      T: Cardinal;
    begin
      Inc(R, 8);
      T := GetTickCount;
      for I := 0 to 360 - 1 do begin
        CenterRadiusPoint(AX, AY, I, R, X, Y);
        Canvas.Pixels[X, Y] := 0;
      end;
      T := GetTickCount - T;
      Canvas.TextOut(10, 10, IntToStr(T));
    end;
    
    end.
  • 相关阅读:
    nodejs express搭建一个网站整理
    nodejs http post 请求带参数
    express respond.send 和 end的区别
    .net程序员做的第一个安卓APP
    angularjs ui-grid如何动态设置行高
    错误处理(Operation Result)方法
    jquery validation yyyy-MM-dd格式日期在ie中无法验证通过
    PAT (Basic Level) Practise (中文)- 1010. 一元多项式求导 (25)
    PAT (Basic Level) Practise (中文)- 1007. 素数对猜想 (20)
    PAT (Basic Level) Practise (中文)- 1012. 数字分类 (20)
  • 原文地址:https://www.cnblogs.com/yangyxd/p/5146701.html
Copyright © 2011-2022 走看看