可编程式坐标--单位圆坐标
来源:互联网 发布:sql 创建触发器 编辑:程序博客网 时间:2024/05/14 13:37
介绍
传统的坐标表示方法(x,y)需要手动一个个输入坐标,不便于编程,特别是在画规则图形的时候,有规则的点(x, y), (-x, -y), (nx, ny)明明可以使用程序控制,却还需要手工收入,特麻烦。因此我发明了一种可编程的坐标表示方法--单位圆坐标。
理论
任何坐标都能用N * 单位圆与其外切矩形的切点及外切矩形顶点来表示,这些点包括:
( 0, 1 ) -- up
( 1, 1 ) -- upRight
( 1, 0 ) -- right
( 1, -1 ) -- downRight
( 0, -1 ) -- down
( -1, -1 ) -- downLeft
( -1, 0 ) -- left
( -1, 1 ) -- upLeft
因此在程序中,我只要给定值(N)和方向(单位圆坐标)就能制作一个二维坐标。
实现
/**
*Create a point in paperJS by using
the tangent points of an unit circle's enclosing rectangle, * and the vertexes of this enclosing rectangle(directions) multiplied by two any given numbers,
* for example, (4, 2) is (1*4, 1*2), and (23.5, -23.5) is (1, -1) * 23.5 …
*
*author: 杜霖 mcdooooo@gmail.com
*/
unitCircleCoor = {
应用
_Coor_: [{ // up
x: 0,
y: 1
}, { // upRight
x: 1,
y: 1
}, { // right
x: 1,
y: 0
}, { // downRight
x: 1,
y: -1
}, { // down
x: 0,
y: -1
}, { // downLeft
x: -1,
y: -1
}, { // left
x: -1,
y: 0
}, { // upLeft
x: -1,
y: 1
}],
directions: [ "up", "upRight", "right", "downRight", "down", "downLeft", "left", "upLeft" ],
_getCoorX: function( valX, direct ) {
var index = this.directions.indexOf( direct );
return ( -1 == index ) ? -99999 : this._Coor_[ index ].x * valX;
},
_getCoorY: function( valY, direct ) {
var index = this.directions.indexOf( direct );
return ( -1 == index ) ? -99999 : this._Coor_[ index ].y * valY;
},
/**
* getCoor: return the point that ( X coord of direct * valX, Y coord of direct * valY )
*/
getCoor: function( valX, valY, direct ) {
var coor = [];
coor.push( this._getCoorX( valX, direct ) );
coor.push( this._getCoorY( valY, direct ) );
return coor;
},
/**
* getCoorEqual: return the point that direct * val
* The point is a part of y=x function
*/
getCoorEqual: function( val, direct ) {
return this.getCoor( val, val, direct );
}
};
使用paperJs画规则图形
的代码:
var outerWidht = 50, innerWidth = 12.5, path = new Path();
path.strokeColor = "brown";
/**
* 遍历["up", "upRight", "right", "downRight", "down", "downLeft", "left", "upLeft"]
* "up","right", "down", "left"方向的点使用N=50制作,即(0, 50), (50, 0), (0, -50), (-50, 0)
* "upRight", "downRight", "downLeft", "upLeft"方向的点使用N=12.5制作,即(12.5, 12.5), (12.5, -12.5),
* (-12.5, -12.5), (-12.5, 12.5)
*/
for (var i = 0; i < unitCircleCoor.position.length; i++ ) {
if (0 == i % 2 ) {
path.add(new Point( unitCircleCoor.getCoorEqual( outerWidht, unitCircleCoor.position[i] ) ) );
}else {
path.add(new Point( unitCircleCoor.getCoorEqual( innerWidth, unitCircleCoor.position[i] ) ) );
}
}
path.closed =true;
- 可编程式坐标--单位圆坐标
- 单位,坐标与导出
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- 坐标
- Servlet3 可编程式注册web组件
- kinect各种流的坐标单位,坐标变换
- 逻辑单位与设备坐标(转)
- kinect的坐标单位问题的问题
- FFT变换后,坐标单位是什么?
- JavaScript运算时保留坐标单位
- FFT变换后,坐标单位是什么?
- 我们没有在一起 但认识你也足够好 2012-03-18 10:47:05
- Finance: 投资与投机的区别
- Dalvik Virtual Machine references
- asp.net WebForm 前台获取后台c#代码信息
- 【shell编程】sed 常见练习题总结
- 可编程式坐标--单位圆坐标
- kalman滤波器
- UIView的一些基本方法 init、loadView、viewDidLoad、viewDidUnload、dealloc
- poj 3461 Oulipo(KMP)
- 相机变换矩阵
- DIY一个C++ traits来判断enum是否有用户自定义的operator<<
- 开篇之坚持...
- 看看GtkWindow如何被生出来的(gtk_window_new()的内部机制)
- RS232与RS485的功能与区别!