大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 一些关于点的函数

一些关于点的函数

时间: 2021-07-31 作者:daque

unit functs; interface uses   wintypes, classes, graphics, sysutils; type   tpoint2d = record     x, y: real;   end;   tpoint3d = record     x, y, z: real;   end; function point2d(x, y: real): tpoint2d; function roundpoint(p: tpoint2d): tpoint; function floatpoint(p: tpoint): tpoint2d; function point3d(x, y, z: real): tpoint3d; function angle2d(p: tpoint2d): real; function dist2d(p: tpoint2d): real; function dist3d(p: tpoint3d): real; function relangle2d(pa, pb: tpoint2d): real; function reldist2d(pa, pb: tpoint2d): real; function reldist3d(pa, pb: tpoint3d): real; procedure rotate2d(var p: tpoint2d; angle2d: real); procedure relrotate2d(var p: tpoint2d; pcentr: tpoint2d; angle2d: real); procedure move2d(var p: tpoint2d; angle2d, distance: real); function between(pa, pb: tpoint2d; preference: real): tpoint2d; function distline(a, b, c: real; p: tpoint2d): real; function dist2p(p, p1, p2: tpoint2d): real; function distd1p(dx, dy: real; p1, p: tpoint2d): real; function nearline2p(p, p1, p2: tpoint2d; d: real): boolean; function addpoints(p1, p2: tpoint2d): tpoint2d; function subpoints(p1, p2: tpoint2d): tpoint2d; function invert(col: tcolor): tcolor; function dark(col: tcolor; percentage: byte): tcolor; function light(col: tcolor; percentage: byte): tcolor; function mix(col1, col2: tcolor; percentage: byte): tcolor; function mmix(cols: array of tcolor): tcolor; function log(base, value: real): real; function modulator(val, max: real): real; function m(i, j: integer): integer; function tan(angle2d: real): real; procedure limit(var value: integer; min, max: integer); function exp2(exponent: byte): word; function getsysdir: string; function getwindir: string; implementation function point2d(x, y: real): tpoint2d; begin   point2d.x := x;   point2d.y := y; end; function roundpoint(p: tpoint2d): tpoint; begin   roundpoint.x := round(p.x);   roundpoint.y := round(p.y); end; function floatpoint(p: tpoint): tpoint2d; begin   floatpoint.x := p.x;   floatpoint.y := p.y; end; function point3d(x, y, z: real): tpoint3d; begin   point3d.x := x;   point3d.y := y;   point3d.z := z; end; function angle2d(p: tpoint2d): real; begin   if p.x = 0 then   begin     if p.y > 0 then result := pi / 2;     if p.y = 0 then result := 0;     if p.y < 0 then result := pi / -2; end else result := arctan(p.y / p.x); if p.x < 0 then begin if p.y < 0 then result := result + pi; if p.y >= 0 then result := result - pi;   end;   if result < 0 then result := result + 2 * pi; end; function dist2d(p: tpoint2d): real; begin result := sqrt(p.x * p.x + p.y * p.y); end; function dist3d(p: tpoint3d): real; begin dist3d := sqrt(p.x * p.x + p.y * p.y + p.z * p.z); end; function relangle2d(pa, pb: tpoint2d): real; begin relangle2d := angle2d(point2d(pb.x - pa.x, pb.y - pa.y)); end; function reldist2d(pa, pb: tpoint2d): real; begin result := dist2d(point2d(pb.x - pa.x, pb.y - pa.y)); end; function reldist3d(pa, pb: tpoint3d): real; begin reldist3d := dist3d(point3d(pb.x - pa.x, pb.y - pa.y, pb.z - pa.z)); end; procedure rotate2d(var p: tpoint2d; angle2d: real); var temp: tpoint2d; begin temp.x := p.x * cos(angle2d) - p.y * sin(angle2d); temp.y := p.x * sin(angle2d) + p.y * cos(angle2d); p := temp; end; procedure relrotate2d(var p: tpoint2d; pcentr: tpoint2d; angle2d: real); var temp: tpoint2d; begin temp := subpoints(p, pcentr); rotate2d(temp, angle2d); p := addpoints(temp, pcentr); end; procedure move2d(var p: tpoint2d; angle2d, distance: real); var temp: tpoint2d; begin temp.x := p.x + (cos(angle2d) * distance); temp.y := p.y + (sin(angle2d) * distance); p := temp; end; function between(pa, pb: tpoint2d; preference: real): tpoint2d; begin between.x := pa.x * preference + pb.x * (1 - preference); between.y := pa.y * preference + pb.y * (1 - preference); end; function distline(a, b, c: real; p: tpoint2d): real; begin result := (a * p.x + b * p.y + c) / sqrt(sqr(a) + sqr(b)); end; function dist2p(p, p1, p2: tpoint2d): real; begin result := distline(p1.y - p2.y, p2.x - p1.x, -p1.y * p2.x + p1.x * p2.y, p); end; function distd1p(dx, dy: real; p1, p: tpoint2d): real; begin result := distline(dy, -dx, -dy * p1.x + dx * p1.y, p); end; function nearline2p(p, p1, p2: tpoint2d; d: real): boolean; begin result := false; if distd1p(-(p2.y - p1.y), p2.x - p1.x, p1, p) * distd1p(-(p2.y - p1.y), p2.x - p1.x, p2, p) <= 0 then if abs(dist2p(p, p1, p2)) < d then result := true; end; function addpoints(p1, p2: tpoint2d): tpoint2d; begin addpoints := point2d(p1.x + p2.x, p1.y + p2.y); end; function subpoints(p1, p2: tpoint2d): tpoint2d; begin subpoints := point2d(p1.x - p2.x, p1.y - p2.y); end; function invert(col: tcolor): tcolor; begin invert := not col; end; function dark(col: tcolor; percentage: byte): tcolor; var r, g, b: byte; begin r := getrvalue(col); g := getgvalue(col); b := getbvalue(col); r := round(r * percentage / 100); g := round(g * percentage / 100); b := round(b * percentage / 100); dark := rgb(r, g, b); end; function light(col: tcolor; percentage: byte): tcolor; var r, g, b: byte; begin r := getrvalue(col); g := getgvalue(col); b := getbvalue(col); r := round(r * percentage / 100) + round(255 - percentage / 100 * 255); g := round(g * percentage / 100) + round(255 - percentage / 100 * 255); b := round(b * percentage / 100) + round(255 - percentage / 100 * 255); light := rgb(r, g, b); end; function mix(col1, col2: tcolor; percentage: byte): tcolor; var r, g, b: byte; begin r := round((getrvalue(col1) * percentage / 100) + (getrvalue(col2) * (100 - percentage) / 100)); g := round((getgvalue(col1) * percentage / 100) + (getgvalue(col2) * (100 - percentage) / 100)); b := round((getbvalue(col1) * percentage / 100) + (getbvalue(col2) * (100 - percentage) / 100)); mix := rgb(r, g, b); end; function mmix(cols: array of tcolor): tcolor; var i, r, g, b, length: integer; begin length := high(cols) - low(cols) + 1; r := 0; g := 0; b := 0; for i := low(cols) to high(cols) do begin r := r + getrvalue(cols[i]); g := g + getgvalue(cols[i]); b := b + getbvalue(cols[i]); end; r := r div length; g := g div length; b := b div length; mmix := rgb(r, g, b); end; function log(base, value: real): real; begin log := ln(value) / ln(base); end; function power(base, exponent: real): real; begin power := ln(base) * exp(exponent); end; function modulator(val, max: real): real; begin modulator := (val / max - round(val / max)) * max; end; function m(i, j: integer): integer; begin m := ((i mod j) + j) mod j; end; function tan(angle2d: real): real; begin tan := sin(angle2d) / cos(angle2d); end; procedure limit(var value: integer; min, max: integer); begin if value < min then value := min; if value > max then value := max; end; function exp2(exponent: byte): word; var   temp, i: word; begin   temp := 1;   for i := 1 to exponent do     temp := temp * 2;   result := temp; end; function getsysdir: string; var   temp: array[0..255] of char; begin   getsystemdirectory(temp, 256);   result := strpas(temp); end; function getwindir: string; var   temp: array[0..255] of char; begin   getwindowsdirectory(temp, 256);   result := strpas(temp); end; end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.