一条直线与一个以C (cx,cy)
为中心,半径为r
的圆相交。该线由位置P (px, py)
和方向D (dx, dy)
描述。 P
位于圆内,直线无限长。 d
到交点的距离P
是多少?
float Intersect(Vector2d C, float r, Vector2d P, Vector2d D){
...
return d;
}
答案 0 :(得分:1)
您可以展开括号并求解未知[
{
"eventType": "VIEW_CLICKED",
"timestamp": 1560409968465,
"replacementText": "",
"actionCode": -1,
"delayTime": 0,
"canScrollTo": false,
"elementDescriptors": [
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": 2,
"adapterViewChildPosition": -1,
"groupViewChildPosition": -1,
"resourceId": "com.example.myapplication:id/layoutAccounts",
"contentDescription": "",
"text": ""
},
{
"className": "android.support.v7.widget.RecyclerView",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/Primary_recycler_view",
"contentDescription": "",
"text": ""
},
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/relative2",
"contentDescription": "",
"text": ""
}
]
},
{
"eventType": "VIEW_CLICKED",
"timestamp": 1560409976951,
"replacementText": "",
"actionCode": -1,
"delayTime": 0,
"canScrollTo": false,
"elementDescriptors": [
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": 15,
"adapterViewChildPosition": -1,
"groupViewChildPosition": -1,
"resourceId": "com.example.myapplication:id/layoutAccounts",
"contentDescription": "",
"text": ""
},
{
"className": "android.support.v7.widget.RecyclerView",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/Primary_recycler_view",
"contentDescription": "",
"text": ""
},
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/relative2",
"contentDescription": "",
"text": ""
}
]
},
{
"eventType": "VIEW_CLICKED",
"timestamp": 1560409984752,
"replacementText": "",
"actionCode": -1,
"delayTime": 0,
"canScrollTo": false,
"elementDescriptors": [
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": 25,
"adapterViewChildPosition": -1,
"groupViewChildPosition": -1,
"resourceId": "com.example.myapplication:id/layoutAccounts",
"contentDescription": "",
"text": ""
},
{
"className": "android.support.v7.widget.RecyclerView",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/Primary_recycler_view",
"contentDescription": "",
"text": ""
},
{
"className": "android.widget.RelativeLayout",
"recyclerViewChildPosition": -1,
"adapterViewChildPosition": -1,
"groupViewChildPosition": 0,
"resourceId": "com.example.myapplication:id/relative2",
"contentDescription": "",
"text": ""
}
]
}
]
的二次方程式:
t
如果对((px - cx) + t * dx)^2 + ((py - cy) + t * dy)^2 = r^2
向量进行了归一化(单位长度),则需要(dx,dy)
(如果您的线是真正的光线从圆圈开始,则为正根)的距离。
交点公式(当前语句中不需要)
t