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.
  • 相关阅读:
    一个高级的makefile文件
    poj3616题(动态规划),看了别人的提示,自己又写了一遍
    浅谈C++ IO标准库(1)
    https证书安装踩坑
    一个简单通知服务的开发和搭建
    WCF学习笔记
    线程(Thread)、线程池(ThreadPool)技术
    BackgroundWorker与线程使用
    使用ITextSharp生成PDF文件心得
    值类型与引用类型
  • 原文地址:https://www.cnblogs.com/yangyxd/p/5146701.html
Copyright © 2011-2022 走看看