如何在 MATLAB 中求角度平分线

发布于 2024-09-27 09:37:25 字数 529 浏览 3 评论 0原文

我有一个与此代码相关的问题:

t = -20:0.1:20; 
plot3(zeros(size(t)),t,-t.^2);
grid on
hold on
i = 1;
h = plot3([0 0],[0 t(i)],[0 -t(i)^2],'r');
h1 = plot3([-1 0],[0 0],[-400 -200],'g');
for(i=2:length(t))
    set(h,'xdata',[-1 0],'ydata',[0 t(i)],'zdata',[-400 -t(i)^2]);    
    pause(0.01);
end

在这段代码中,我绘制了两条相交线。 H1 和 H2。 H1 是固定的,H2 作为时间的函数移动。在这个例子中,H2 碰巧画出了一条抛物线,但它的运动可能是任意的。

如何计算并绘制线 H2 的每个位置的这两条相交线之间的角度平分线?我希望在图中看到平分线和线 H2 同时移动。

针对 H2 的一个位置解决此问题就足够了,因为对于 H2 相对于 H1 的所有方向来说,过程都是相同的。

I have a question connected to this code:

t = -20:0.1:20; 
plot3(zeros(size(t)),t,-t.^2);
grid on
hold on
i = 1;
h = plot3([0 0],[0 t(i)],[0 -t(i)^2],'r');
h1 = plot3([-1 0],[0 0],[-400 -200],'g');
for(i=2:length(t))
    set(h,'xdata',[-1 0],'ydata',[0 t(i)],'zdata',[-400 -t(i)^2]);    
    pause(0.01);
end

In this code, I plot two intersecting lines. H1, and H2. H1 is fixed, H2 moves as a function of time. H2 happens to trace a parabola in this example, but its movement could be arbitrary.

How can I calculate and draw the bisector of the angle between these two intersecting lines for every position of the line H2? I would like to see in the plot the bisector and the line H2 moving at the same time.

Solving this problem for one position of H2 is sufficient, since it will be the same procedure for all orientations of H2 relative to H1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浮世清欢 2024-10-04 09:37:25

我不是几何天才,可能有一种更简单的方法可以做到这一点。截至目前,还没有人做出回应,所以这将是一件大事。

你在三个空间中有三个点:
设 A 为两条线段的公共顶点。
设 B 和 C 为两条线段上的两个已知点。

选择任意距离 r,其中

r <= 从 A 到 B 的距离

r <= 从 A 到 C 的距离

沿线段 AB 从 A 测量距离 r。这是RB点
从 A 沿线段 AC 测量距离或 r。这是点 RC

求连接 RB 和 RC 的线段的中点。这是点M

线段AM 是角CAB 的角平分线。


每个步骤都应该相对容易完成。

I am not a geometry genius, there is likely an easier way to do this. As of now, no one has responded though, so this will be something.

You have three points in three space:
Let A be the common vertice of the two line segments.
Let B and C be two known points on the two line segments.

Choose an arbitrary distance r where

r <= distance from A to B

r <= distance from A to C

Measure from A along line segment AB a distance of r. This is point RB
Measure from A along line segment AC a distance or r. This is point RC

Find the mid point of line segment connecting RB and RC. This is point M

Line segment AM is the angular bisector of angle CAB.


Each of these steps should be relatively easy to accomplish.

倾其所爱 2024-10-04 09:37:25

这基本上是 MatlabDoug 的方法,对他称为 M 的点的确定进行了一些改进。

t = -20:0.1:20;
plot3(zeros(size(t)),t,-t.^2);
grid on
hold on

v1 = [1 0 200];
v1 = v1/norm(v1);

i = 1;

h = plot3([-1 0],[0 t(i)],[-400 -t(i)^2],'r');
h1 = plot3([-1 0],[0 0],[-400 -200],'g');

l = norm([1 t(i) -t(i)^2+400]);
p = l*v1 + [-1 0 -400];
v2 = (p + [0 t(i) -t(i)^2])/2 - [-1 0 -400];
p2 = [-1 0 -400] + v2/v2(1);
h2 = plot3([-1 p2(1)],[0 p2(2)],[-400 p2(3)],'m');

pause(0.1)

for(i=2:length(t))
    l = norm([1 t(i) -t(i)^2+400]);
    p = l*v1 + [-1 0 -400];
    v2 = (p + [0 t(i) -t(i)^2])/2 - [-1 0 -400];
    p2 = [-1 0 -400] + v2/v2(1);

    set(h,'xdata',[-1 0],'ydata',[0 t(i)],'zdata',[-400 -t(i)^2]);
    set(h2,'xdata',[-1 p2(1)],'ydata',[0 p2(2)],'zdata',[-400 p2(3)]);

    pause;
end

Here is basically MatlabDoug's method with some improvement on the determination of the point he calls M.

t = -20:0.1:20;
plot3(zeros(size(t)),t,-t.^2);
grid on
hold on

v1 = [1 0 200];
v1 = v1/norm(v1);

i = 1;

h = plot3([-1 0],[0 t(i)],[-400 -t(i)^2],'r');
h1 = plot3([-1 0],[0 0],[-400 -200],'g');

l = norm([1 t(i) -t(i)^2+400]);
p = l*v1 + [-1 0 -400];
v2 = (p + [0 t(i) -t(i)^2])/2 - [-1 0 -400];
p2 = [-1 0 -400] + v2/v2(1);
h2 = plot3([-1 p2(1)],[0 p2(2)],[-400 p2(3)],'m');

pause(0.1)

for(i=2:length(t))
    l = norm([1 t(i) -t(i)^2+400]);
    p = l*v1 + [-1 0 -400];
    v2 = (p + [0 t(i) -t(i)^2])/2 - [-1 0 -400];
    p2 = [-1 0 -400] + v2/v2(1);

    set(h,'xdata',[-1 0],'ydata',[0 t(i)],'zdata',[-400 -t(i)^2]);
    set(h2,'xdata',[-1 p2(1)],'ydata',[0 p2(2)],'zdata',[-400 p2(3)]);

    pause;
end
热鲨 2024-10-04 09:37:25

我只是使用以下内容:

  1. 找到归一化向量 AB 和 AC,其中 A 是线段的公共点。
  2. V = (AB + AC) * 0.5 // 生成平分 AB 和 AC 的方向向量。

对 V 进行归一化,然后进行 A + V * 长度,得到从公共点开始的所需长度的线段。

(请注意,此方法不适用于沿一条线的 3 个点来生成垂直平分线,在这种情况下,它将生成一个没有长度的向量)

我添加了一个 C# 实现(在 XZ 平面中使用 Unity 3D Vector3 结构)处理垂直平分线和反射平分线,以防了解 MATLAB 的人可以翻译它。

    public Vector3 GetBisector(Vector3 center, Vector3 first, Vector3 second)
    {
        Vector3 firstDir = (first - center).normalized;
        Vector3 secondDir = (second - center).normalized;
        Vector3 result = ((firstDir + secondDir) * 0.5f).normalized;
        if (IsGreaterThan180(-firstDir, secondDir))
        {
            // make into a reflex vector
            (result.x, result.z) = (-result.x, -result.z);
        }
        if (result.sqrMagnitude < 0.99f)
        {
            // we have a colinear set of lines.
            // return the perpendicular bisector.
            result = Vector3.Cross(Vector3.up, -firstDir).normalized;
        }
        return result;
    }

    bool IsGreaterThan180(Vector3 dir, Vector3 dir2)
    {
        // < 0.0 for clockwise ordering
        return (dir2.x * dir.z - dir2.z * dir.x) < 0.0f;
    }

另请注意,返回的平分线是单位长度的向量。使用“中心+平分线*长度”可以将其放置到世界空间中。

I just use the following:

  1. Find the normalized vectors AB, and AC, where A is the common point of the segments.
  2. V = (AB + AC) * 0.5 // produces the direction vector that bisects AB and AC.

Normalize V, then do A + V * length to get the line segment of the desired length that starts at the common point.

(Note that this method does not work on 3 points along a line to produce a perpendicular bisector, it will yield a vector with no length in that case)

I have added a C# implementation (in the XZ plane using Unity 3D Vector3 struct) that handles Perpendicular and Reflex bisectors in case someone that knows MATLAB would translate it.

    public Vector3 GetBisector(Vector3 center, Vector3 first, Vector3 second)
    {
        Vector3 firstDir = (first - center).normalized;
        Vector3 secondDir = (second - center).normalized;
        Vector3 result = ((firstDir + secondDir) * 0.5f).normalized;
        if (IsGreaterThan180(-firstDir, secondDir))
        {
            // make into a reflex vector
            (result.x, result.z) = (-result.x, -result.z);
        }
        if (result.sqrMagnitude < 0.99f)
        {
            // we have a colinear set of lines.
            // return the perpendicular bisector.
            result = Vector3.Cross(Vector3.up, -firstDir).normalized;
        }
        return result;
    }

    bool IsGreaterThan180(Vector3 dir, Vector3 dir2)
    {
        // < 0.0 for clockwise ordering
        return (dir2.x * dir.z - dir2.z * dir.x) < 0.0f;
    }

Also note that the returned bisector is a vector of unit length. Using "center + bisector * length" could be used to place it into worldspace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文