
我得到了两个圆的(x,y)中心位置及其半径,但我需要使用JavaScript找到它们的交点(用红色标记).
我认为就数学而言最好的解释是在这里找到的(两个圆圈的交点),但我并不真正理解数学,所以我无法实现它.
例如,d = || P1 - P0 || 什么做了|| 代表?这是否意味着最终的数字总是积极的?
并且P2 = P0 + a(P1-P0)/ d,这里的P不是(10,50)?但是在JavaScript中执行(10,50)+13会给你63,所以它只是忽略了第一个数字,那么假设会发生什么?结果应该是(23,63)这里还是?还有P1-P0部分或(40,30) - (10,60),您如何在JavaScript中表达?
有没有办法Rscript -e在多行中提供代码?
这在香草R中是可能的
R --vanilla <<code
a <- "hello\n"
cat(a)
code
Run Code Online (Sandbox Code Playgroud)
但Rscript根据R版本,我使用两种不同的东西.
# R 3.0.2 gives two ignores
Rscript -e '
quote> a <- 3+3
quote> cat(a, "\n")
quote> '
# ARGUMENT 'cat(a,~+~"' __ignored__
# ARGUMENT '")' __ignored__
Rscript -e 'a <- 3+3;cat(a, "\n")'
# ARGUMENT '")' __ignored__
# R 2.15.3 gives an ignore for the multiline, but it works with semicolons
Rscript -e '
quote> a <- 3+3
quote> cat(a, "\n")
quote> '
# ARGUMENT …Run Code Online (Sandbox Code Playgroud) 我有一个范围内的矢量 [1,10]
c(1,2,9,10)
Run Code Online (Sandbox Code Playgroud)
我希望将它映射到不同的范围,例如 [12,102]
c(12,22,92,102)
Run Code Online (Sandbox Code Playgroud)
是否有一个功能已经在R中执行此操作?
我正在等待无限循环中的用户输入(使用'read')并希望有命令历史记录,即能够使用向上和向下箭头键显示已输入的先前输入,而不是获取^ [[A和^ [[B. 这可能吗?
感谢@ l0b0的回答.它让我朝着正确的方向前进.玩了一段时间后,我意识到我还需要以下两个功能,但我还没有设法得到它们:
如果我按下并向上一个命令添加一些内容,我希望将整个内容保存在历史记录中,而不仅仅是添加内容.例
$ ./up_and_down
输入命令:hello
ENTER
输入命令:
Up
输入命令:hello you
ENTER
输入命令:
Up
输入命令:you
(而不是"hello you")
如果我不能继续上升因为我在历史数组的末尾,我不希望光标移动到前一行,而是希望它保持固定.
这是我到目前为止(up_and_down):
#!/usr/bin/env bash
set -o nounset -o errexit -o pipefail
read_history() {
local char
local string
local esc=$'\e'
local up=$'\e[A'
local down=$'\e[B'
local clear_line=$'\r\e[K'
local history=()
local -i history_index=0
# Read one character at a time
while IFS="" read -p "Enter command:" -n1 -s char ; do
if [[ "$char" == "$esc" ]]; then
# Get the rest …Run Code Online (Sandbox Code Playgroud) 我正在加载一个名为的第三方库sorted-array并像这样使用它:
import SortedArray from 'sorted-array';
export class Selector {
private mySortedArray!: SortedArray;
constructor() {
this.mySortedArray = new SortedArray();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到此错误: Cannot use namespace 'SortedArray' as a type.ts(2709)
所以,我创建了这个文件:
// src/typings/sorted-array/index.d.ts
declare module 'sorted-array' {
class SortedArray {
constructor(arr: number[]);
search(element: any): number;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,错误仍然存在。我究竟做错了什么?
我试过了
d3.select(".cell:first")
d3.selectAll(".cell").filter(":first")
d3.selectAll(".cell").select(":first")
Run Code Online (Sandbox Code Playgroud)
但都没有工作
我想将工具提示向右移动几个像素,因此箭头位于光标所在单元格的中心(当前,它位于(0,0),即左上角).这是我的代码:
$("rect.cell").tooltip({
title: "hola",
placement: "top"
});
Run Code Online (Sandbox Code Playgroud)
和图像:

理想情况下我想使用javascript来做这件事,所以如果我改变单元格的大小,我可以更新像素数.
我想生成两个不同大小的图像,但是并排显示它们.这可能吗?
这有效,但是它们必须是相同的大小:
```{r two_plots_same_size_side_by_side, fig.width=5, fig.height=5}
plot(...)
plot(...)
```
Run Code Online (Sandbox Code Playgroud)
这不起作用,但是因为在Markdown中,由单个换行符分隔的行显示在同一行上.
```{r normal_plot, fig.width=5, fig.height=5}
plot(...)
```
```{r tall_plot, fig.width=5, fig.height=9}
plot(...)
```
Run Code Online (Sandbox Code Playgroud) 如此答案所示,可以使用bash中的readReadline(-e)通过使用向上和向下键返回以前的历史记录项:
#! /usr/bin/env bash
while IFS="" read -p "input> " -e line; do
history -s "$line" # append $line to local history
done
Run Code Online (Sandbox Code Playgroud)
在zsh中执行此操作的正确方法是什么?(在循环中获取用户输入并允许上/下键历史记录完成).这不起作用:
#! /usr/bin/env zsh
while IFS="" vared -p "input> " -c line; do
done
Run Code Online (Sandbox Code Playgroud)
我认为在zsh中的脚本默认禁用历史记录完成.另外,我不希望历史记录来自shell,而是来自脚本中输入的输入.
我正在使用D3函数each,它接受一个回调函数并调用它this作为参数传递,但我需要同时访问this和_this.这是coffeescript代码:
@x = d3.scale.ordinal().domain(d3.range(@model.geneExpressions[0].length)).rangeBands([0, width])
getRow = (row) =>
cell = d3.select(this).selectAll(".cell")
.data(row)
.enter().append("rect")
.attr("x", (d,i) => @x(i))
rows = @heatmap.selectAll(".row")
.data(@model.geneExpressions)
.enter().append("g")
.each(getRow)
Run Code Online (Sandbox Code Playgroud)
以及它生成的javascript:
var _this = this;
this.x = d3.scale.ordinal().domain(d3.range(this.model.geneExpressions[0].length)).rangeBands([0, width]);
getRow = function(row) {
var cell;
return cell = d3.select(_this).selectAll(".cell").data(row).enter().append("rect").attr("x", function(d, i) {
return _this.x(i);
})
};
rows = this.heatmap.selectAll(".row").data(this.model.geneExpressions).enter().append("g").attr("class", "row").each(getRow);
Run Code Online (Sandbox Code Playgroud)
我怎样才能this在这一行中使用coffeescript 并保持一致?:
return cell = d3.select(this) ...
Run Code Online (Sandbox Code Playgroud)
问题是我无法将@x作为参数传递给each并使用细箭头而不是胖箭头(因为那时我无法访问@x),除非我重写D3函数,这似乎有点过分.
r ×3
d3.js ×2
javascript ×2
shell ×2
bash ×1
coffeescript ×1
completion ×1
dom ×1
geometry ×1
history ×1
jquery ×1
knitr ×1
rscript ×1
stdin ×1
svg ×1
tooltip ×1
typescript ×1
zsh ×1