var myarray=[
'0000000000000000000000000000000000000000000000000000',
'0000000000000000010000000000000000000000000000000000',
'0000000000000000100000000000000000000000000000000000',
'0000000000000001000000000000000000000000000000000000',
'0000000000000010000000000000000000000000000000000000',
'0000000000000100000000000000000000000000000000000000',
'0000000000001000000000000000000000000000000000000000',
'0000000000010000000000000000000000000000000000000000',
'0000000000100000000000000000000000000000000000000000',
'0000000001000000000000000000000000000000000000000000',
'0000000010000000000000000000000000000000000000000000',
'0000000100000000000000000000000000000000000000000000',
'0000001000000000000000000000000000000000000000000000',
'0000000000000000000000000000000000000000000000000000',
]
我有一个像上面这样的数组,包括一条具有特定旋转角度的直线(45° in this case
),我知道线的所有点,因为我有一个数组,其中包含所有坐标,即line('1'
- characters)。
var positions=[
[6,12],
[7,11],
[8,10],
[9,9],
[10,8],
[11,7],
[12,6],
[13,5],
[14,4],
[15,3],
[16,2],
[17,1],
]
我也知道线旋转角度:
var angle=45
我想得到的是绘制线条(position array
)和normal
的特定坐标,以便我的阵列看起来像这样:
(用'2 标示的法线与'1 符号化的起始线有一个直角,并且必须达到特定长度这种情况~16
)
var starting_coordinate=[11,7]
var myarray=[
'0000000000000000000000000000000000000000000000000000',
'0000000000000000010000000000000000000000000000000000',
'0000000000000000100000000000000000000000000000000000',
'0000020000000001000000000000000000000000000000000000',
'0000002200000010000000000000000000000000000000000000',
'0000000220000100000000000000000000000000000000000000',
'0000000002201000000000000000000000000000000000000000',
'0000000000212000000000000000000000000000000000000000',
'0000000000100220000000000000000000000000000000000000',
'0000000001000002200000000000000000000000000000000000',
'0000000010000000022000000000000000000000000000000000',
'0000000100000000000200000000000000000000000000000000',
'0000001000000000000000000000000000000000000000000000',
'0000000000000000000000000000000000000000000000000000',
]
如何计算“2”的行的位置并将它们绘制到矩阵中?
var myarray=[
'0000000000000000000000000000000000000000000000000000',
'0000000000000000010000000000000000000000000000000000',
'0000000000000000100000000000000000000000000000000000',
'0000000000000001000000000000000000000000000000000000',
'0000000000000010000000000000000000000000000000000000',
'0000000000000100000000000000000000000000000000000000',
'0000000000001000000000000000000000000000000000000000',
'0000000000010000000000000000000000000000000000000000',
'0000000000100000000000000000000000000000000000000000',
'0000000001000000000000000000000000000000000000000000',
'0000000010000000000000000000000000000000000000000000',
'0000000100000000000000000000000000000000000000000000',
'0000001000000000000000000000000000000000000000000000',
'0000000000000000000000000000000000000000000000000000',
]
function draw_tangente(array, angle, length, x, y) {
var radians=(Math.PI / 180) * angle
for (var i=0; i<length; i++) {
var new_x = Math.round(Math.cos(radians)*(x-i))
var new_y = Math.round(Math.sin(radians)*(y-i))
try {
var point = array[new_y].split('');point[new_x] = '2';array[new_y] = point.toString().replace(/,/g,'');
} catch(e) {}
}
return array;
}
console.log(draw_tangente(myarray, 45, 10, 11, 7).join('\n'));