Unity 一条线在另一条线的投影

不知道,大家有没有对 Unity的坐标 和 向量的关系 产生 过疑问?

其实他的坐标就是向量,

这张图里面就有四个点 Zero, P0,P1 和 P2,  他们的关系相信大家都知道, 三角型法则, 两个向量相加等于 第三个向量。 所以  Vercter(Zer0, P0) = Vercter(p0, p1) + Vercter(Zero, P1 ), 其他的关系 以此类推。


昨天上午需要一个功能 求一条线 在另外一天线上的 一个点:


这条绿色的线就是我要求的点;


<span style="font-size:24px;">using UnityEngine;
using System.Collections;

public class LineProcess : MonoBehaviour {

    public Transform p1, p2;
    public Transform p0;
    public Transform pZero;
    public Vector3 V1, V2;
    public Vector3 Vproject;
    public Vector3 VHor;

    // Use this for initialization
    void Start () {
 
	
	}
	
	// Update is called once per frame
	void Update () {
        V1  = p0.position - p1.position;
        V2  = p2.position - p1.position;

        Debug.DrawLine( pZero.position,  p0.position, Color.magenta );
        Debug.DrawLine( pZero.position,  p1.position, Color.magenta );
        Debug.DrawLine( pZero.position,  p2.position, Color.magenta );


        Debug.DrawLine(p0.position, p1.position, Color.blue);
        Debug.DrawLine(p1.position, p2.position, Color.gray);
        Debug.DrawLine(p2.position, p0.position, Color.yellow);


        Vproject = Vector3.Project( V1, V2 );
        VHor     = Vproject - V1 ;

   

        Debug.DrawLine(p0.position, VHor+ p0.position, Color.green);

    }
}
</span>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nicepainkiller

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值