计算一条线的法线 [英] Calculate a point normal to a line

查看:192
本文介绍了计算一条线的法线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由(x1,y1)(x2,y2)指定的行L,并且想要计算这个点的
坐标:

    位于法线上的
  • 位于与其长度的一半相交处的法线上
  • 与L
    <例如:


    • 如果行是(x1,a)(x2,a )(水平)
      计算点的坐标为((x2-x1)/ 2,D)。如果线是(a,y1)(a ,y2)(vertical),计算的
      点的坐标为(D,(y2-y1)/ 2)。


      但是我不知道如何以所有
      行的通用方式计算坐标,而不考虑角度(-Pi到Pi)。

      谢谢

      解决方案

      两点之间的中心点由

      ((x1 + x2)/ 2,(y1 + y2)/ 2)

      ,而(非标准化)法线是

       ( - (y2-y1 ),(x2-x1))

      如果我们对这个向量进行归一化,我们得到 $ b ( - (y2-y1),(x2-x1))/ sqrt((x2-x1)^ 2 +(y2-y1)^ 2)(b2 b1
      $ b pre $ )

      如果我们将两者结合起来,我们可以找到两点
      $ b (x1 + x2)/ 2,(y1 + y2)/ 2)+ - D *( - (y2-y1),(x2-x1))/ sqrt((x2-x1)^ 2 +(y2-y1)^ 2)

      您的要求。


      I have a line L specified by (x1,y1)(x2,y2) and want to calculate the coordinates of the point that is:

      • located on the normal that intersects L at the half of its length
      • is a certain distance D away from L

      Examples:

      • If the line is (x1,a)(x2,a) (horizontal) the coordinates of the calculated point would be ((x2-x1)/2,D).
      • If the line is (a,y1)(a,y2) (vertical) the coordinates of the calculated point would be (D, (y2-y1)/2).

      But i dont know how to calculate the coordinates in a generic way for all lines regardless of the angle (-Pi to Pi).

      Thanks in advance!

      解决方案

      The center between both points is given by

      ((x1+x2)/2, (y1+y2)/2)
      

      while the (unnormalized) normal is

      (-(y2-y1), (x2-x1))
      

      If we normalize this vector we get

      (-(y2-y1), (x2-x1)) / sqrt((x2-x1)^2+(y2-y1)^2)
      

      and if we combine both we find the two points

      ((x1+x2)/2, (y1+y2)/2) +- D * (-(y2-y1), (x2-x1)) / sqrt((x2-x1)^2+(y2-y1)^2)
      

      which both fulfill your requirements.

      这篇关于计算一条线的法线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆