无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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)論 (共 條)

分享到微博請遵守國家法律
琼海市| 乌拉特后旗| 通海县| 姜堰市| 平顶山市| 临西县| 株洲市| 泗阳县| 冷水江市| 德安县| 黄大仙区| 闵行区| 揭东县| 顺平县| 苍南县| 辽源市| 北安市| 常山县| 江永县| 开江县| 武宣县| 织金县| 临湘市| 建阳市| 永清县| 上蔡县| 葫芦岛市| 日土县| 宁都县| 五寨县| 绥宁县| 沅陵县| 汉寿县| 禹州市| 华池县| 包头市| 南城县| 广元市| 宽甸| 深泽县| 万年县|