最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

輪子:UE4中計(jì)算直線和圓的交點(diǎn)

2023-06-06 17:58 作者:小強(qiáng)強(qiáng)  | 我要投稿

UE4.18中只提供了判斷直線和圓是否相交的API(FMath::LineSphereIntersection),現(xiàn)在有個(gè)需求要求交點(diǎn),只能自己動(dòng)手寫了


TArray<FVector> LineSphereIntersection(const FVector& LineOrigin, const FVector& LineDir, const FVector& circleOrigin, float radius)?

{

????TArray<FVector> IntersectionPoints;

????// 求圓心到直線最近的點(diǎn)

????FVector CloestPoint = FMath::ClosestPointOnLine(LineOrigin, LineDir, circleOrigin);?

? ?// 圓心到直線的距離

???float dist = (CloestPoint - circleOrigin).Size();

? ?if(dist > radius)?

? ?{

? ? ? ?// 距離大于圓的半徑,沒有交點(diǎn)

? ?}

? ?else if(dist == radius)

? ?{

?? ? ? ?// 距離等于半徑,交點(diǎn)就是最近的點(diǎn)

?? ? ? ?IntersectionPoints.Add(ClosestPoint);

? ? }

? ?else

? ?{?

? ? ? ?// 距離小于半徑,交點(diǎn)有2個(gè)

?? ? ? ?// 斜邊邊長 = 半徑, 一條直角邊長 = 圓心到直線的距離

?? ? ? ?float HypotenuseLength = FMath::Sqrt(radius * radius - dist * dist);

? ? ? ?FVector Point1 = ClosestPoint + LineDir * HypotenuseLength;

? ? ? ?IntersectionPoints.Add(Point1);?

? ? ? ?FVector Point2 = ClosestPoint - LineDir * HypotenuseLength;?

? ? ? ?IntersectionPoints.Add(Point2);

? ? ?}

? ? ? ?return IntersectionPoints;

? }



為什么沒有代碼格式的排版……

輪子:UE4中計(jì)算直線和圓的交點(diǎn)的評(píng)論 (共 條)

分享到微博請遵守國家法律
孝感市| 三原县| 阿图什市| 武冈市| 田东县| 巢湖市| 同德县| 宾川县| 含山县| 卓资县| 大关县| 台前县| 华蓥市| 肃宁县| 东明县| 刚察县| 星子县| 台中市| 修武县| 万山特区| 任丘市| 永春县| 昌吉市| 靖江市| 宁阳县| 曲阜市| 大余县| 汨罗市| 安陆市| 麟游县| 蒲江县| 临沂市| 辉县市| 连城县| 上虞市| 沁水县| 安溪县| 洞口县| 海口市| 襄樊市| 同仁县|