定义一个"房间点&QUOT内;从墙上点 [英] Defining an "inside room point" from wall points

查看:256
本文介绍了定义一个"房间点&QUOT内;从墙上点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要,我试过,现在解决了几天的一个棘手的事情帮助。这感觉就像它应该是比较容易的,而我只是失去了一些东西的地方。

I need help with one tricky thing that I've tried to solve for a couple of days now. It feels like it should be relatively easy and that I am simply missing something somewhere.

我有一个数组定义每面墙点(黑点),我想创建一个新的内部点(绿点),每个墙壁点。每个壁点之间和内部点的距离应在600

I have an array defining each wall point (black dots) and I want to create a new inside point (green dots) for each wall point. The distance between each wall point and inside point should be 600.

我做了一个图片显示了我的意思:

I made a picture to show what I mean:

我在写这在JavaScript与WebGL的(ThreeJS)的援助。

I'm writing this in javascript with aid of WebGL (ThreeJS).

推荐答案

我要提出类似大卫的一个解决方案,但使用的顶点,而不是线段。我的解决方案也需要点一致的顺序,所以我会去顺时针排序中。

I'm going to propose a solution similar to David's, but using vertices rather than line segments. My solution also requires a consistent ordering of points, so I'll go with a clockwise ordering as well.

的新内点以下伪code将生成的排序列表(以相同的顺序作为原点):

The following pseudocode will generate an ordered listing (in the same order as that of the original points) of new inside points:

d = 600    // distance of new inside point from wall point
for each 3 consecutive points (a, b, c)
   vector u = a - b; normalize u
   vector v = c - b; normalize v
   w = u + v; normalize w
   if angle (a, b, c) is convex    // cross product is positive: see below
      new inside point = b + (w * d) 
   else    // angle is concave/cross product is negative
      new inside point = b - (w * d)
   end
end

的叉积(U x垂直)由下式给出:

The cross product (u x v) is given by:

(X <子> U * Y <子> v ) - (Y <子> U * X <子> v )

(xu * yv) - (yu * xv)

如果排序是逆时针,叉积的符号是相反的。

If the ordering is counter-clockwise, the signs of the cross product are reversed.

这不检查从试图把新的内点到宽度小于600走廊,如 @ 01zhou 中提到的意见产生冲突。

This does not check for collisions resulting from trying to put new inside points into a corridor of width less than 600, as @01zhou mentions in the comments.

这篇关于定义一个&QUOT;房间点&QUOT内;从墙上点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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