- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一系列矩形,并且知道它们各自 4 个角的确切位置。我想绘制它们并通过它们中的每一个进行放样以创建类似矩形横截面的 3D 管道之类的东西。这些点也不应该限于沿着直轴。应对偏差应灵活。我还想将两端修补封闭。
我在你们的网站上看到了一个关于放样的类似问题,标题为“如何用椭圆放样以在 MATLAB 或 Python 中创建 3d 空心管?”。答案给我留下了深刻的印象,但遗憾的是对于椭圆和圆形。我试图让它与矩形一起工作,但无法弄清楚所需的逻辑。我还尝试将所有东西修补在一起,但这导致了锋利边缘的产生,这是我不想要的。我的代码看起来像这样:
A = importdata(filename);
[size_A, ~] = size(A.data);
axis vis3d;
for i=1:12:size_A-12
X1 = A.data(i+1); X2 = A.data(i+4); X3 = A.data (i+7); X4= A.data (i+10);
Y1 = A.data(i+2); Y2 = A.data(i+5); Y3 = A.data(i+8); Y4 = A.data(i+11);
Z1 = A.data(i+3); Z2 = A.data(i+6); Z3 = A.data(i+9); Z4 = A.data(i+12);
X= [X1;X2;X3;X4];
Y= [Y1;Y2;Y3;Y4];
Z= [Z1;Z2;Z3;Z4];
plot3(X, Y, Z)
patch(X, Y, Z, 'g'); %% for the particular planes
if(i>1) %% for the patching between two planes
A1= [ X1 X1 X2 X4; a1 X4 a2 X3; a2 a4 a3 a3; X2 a1 X3 a4];
B1= [ Y1 Y1 Y2 Y4; b1 Y4 b2 Y3; b2 b4 b3 b3; Y2 b1 Y3 b4];
C1= [ Z1 Z1 Z2 Z4; c1 Z4 c2 Z3; c2 c4 c3 c3; Z2 c1 Z3 c4];
plot3(A1, B1, C1)
patch(A1, B1, C1, 'g');
end
a1=X1; a2=X2; a3=X3; a4=X4;
b1=Y1; b2=Y2; b3=Y3; b4=Y4;
c1=Z1; c2=Z2; c3=Z3; c4=Z4;
figure(1)
grid on
axis equal
hold on
xlabel('x');
ylabel('y');
zlabel('z');
end
最终结果应该像一个具有矩形横截面的非常弯曲的管道。不应有任何尖角。
PS:MATLAB文件正在导入记事本.txt文档,其中将输入坐标,如下所示-
Number_of_sections= 7
X_coordinate= 60.00
Y_coordinate= 13.00
Z_coordinate= -7.50
X_coordinate= 60.00
Y_coordinate= -13.00
Z_coordinate= -7.50
X_coordinate= 60.00
Y_coordinate= -13.00
Z_coordinate= -12.50
X_coordinate= 60.00
Y_coordinate= 13.00
Z_coordinate= -12.50
X_coordinate= 95.00
Y_coordinate= 13.00
Z_coordinate= -7.50
X_coordinate= 95.00
Y_coordinate= -13.00
Z_coordinate= -7.50
X_coordinate= 95.00
Y_coordinate= -13.00
Z_coordinate= -12.50
X_coordinate= 95.00
Y_coordinate= 13.00
Z_coordinate= -12.50
X_coordinate= 95.50
Y_coordinate= 13.50
Z_coordinate= -7.50
X_coordinate= 95.50
Y_coordinate= -13.50
Z_coordinate= -7.50
X_coordinate= 95.50
Y_coordinate= -13.50
Z_coordinate= -12.50
X_coordinate= 95.50
Y_coordinate= 13.50
Z_coordinate= -12.50
X_coordinate= 96.00
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 96.00
Y_coordinate= -14.00
Z_coordinate= -7.50
X_coordinate= 96.00
Y_coordinate= -14.00
Z_coordinate= -12.50
X_coordinate= 96.00
Y_coordinate= 14.00
Z_coordinate= -12.50
X_coordinate= 96.50
Y_coordinate= 14.50
Z_coordinate= -7.50
X_coordinate= 96.50
Y_coordinate= -14.50
Z_coordinate= -7.50
X_coordinate= 96.50
Y_coordinate= -14.50
Z_coordinate= -12.50
X_coordinate= 96.50
Y_coordinate= 14.50
Z_coordinate= -12.50
X_coordinate= 97.00
Y_coordinate= 15.00
Z_coordinate= -7.50
X_coordinate= 97.00
Y_coordinate= -15.00
Z_coordinate= -7.50
X_coordinate= 97.00
Y_coordinate= -15.00
Z_coordinate= -12.50
X_coordinate= 97.00
Y_coordinate= 15.00
Z_coordinate= -12.50
X_coordinate= 99.00
Y_coordinate= 15.00
Z_coordinate= -7.50
X_coordinate= 99.00
Y_coordinate= -15.00
Z_coordinate= -7.50
X_coordinate= 99.00
Y_coordinate= -15.00
Z_coordinate= -12.50
X_coordinate= 99.00
Y_coordinate= 15.00
Z_coordinate= -12.50
X_coordinate= 99.250
Y_coordinate= 14.7500
Z_coordinate= -7.50
X_coordinate= 99.250
Y_coordinate= -15.2500
Z_coordinate= -7.50
X_coordinate= 99.250
Y_coordinate= -15.2500
Z_coordinate= -12.50
X_coordinate= 99.250
Y_coordinate= 14.7500
Z_coordinate= -12.50
X_coordinate= 99.50
Y_coordinate= 14.50
Z_coordinate= -7.50
X_coordinate= 99.50
Y_coordinate= -15.500
Z_coordinate= -7.50
X_coordinate= 99.50
Y_coordinate= -15.500
Z_coordinate= -12.50
X_coordinate= 99.50
Y_coordinate= 14.50
Z_coordinate= -12.50
X_coordinate= 100.0
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 100.0
Y_coordinate= -15.750
Z_coordinate= -7.50
X_coordinate= 100.0
Y_coordinate= -15.750
Z_coordinate= -12.50
X_coordinate= 100.0
Y_coordinate= 14.00
Z_coordinate= -12.50
X_coordinate= 110.0
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 110.0
Y_coordinate= -15.750
Z_coordinate= -7.50
X_coordinate= 110.0
Y_coordinate= -15.750
Z_coordinate= -12.50
X_coordinate= 110.0
Y_coordinate= 14.00
Z_coordinate= -12.50
X_coordinate= 110.0
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 110.0
Y_coordinate= -15.750
Z_coordinate= -7.50
X_coordinate= 120.0
Y_coordinate= -15.750
Z_coordinate= -12.50
X_coordinate= 120.0
Y_coordinate= 14.00
Z_coordinate= -12.50
X_coordinate= 110.0
Y_coordinate= 14.00
Z_coordinate= -5.50
X_coordinate= 110.0
Y_coordinate= -15.750
Z_coordinate= -5.50
X_coordinate= 120.0
Y_coordinate= -15.750
Z_coordinate= -7.50
X_coordinate= 120.0
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 80.0
Y_coordinate= 14.00
Z_coordinate= -5.50
X_coordinate= 80.0
Y_coordinate= -15.750
Z_coordinate= -5.50
X_coordinate= 80.0
Y_coordinate= -15.750
Z_coordinate= -7.50
X_coordinate= 80.0
Y_coordinate= 14.00
Z_coordinate= -7.50
X_coordinate= 70.0
Y_coordinate= 14.00
Z_coordinate= -5.50
X_coordinate= 70.0
Y_coordinate= -15.750
Z_coordinate= -5.50
X_coordinate= 80.0
Y_coordinate= -15.750
Z_coordinate= -5.50
X_coordinate= 80.0
Y_coordinate= 14.00
Z_coordinate= -5.50
X_coordinate= 70.0
Y_coordinate= 14.00
Z_coordinate= -2.50
X_coordinate= 70.0
Y_coordinate= -15.750
Z_coordinate= -2.50
X_coordinate= 80.0
Y_coordinate= -15.750
Z_coordinate= -2.50
X_coordinate= 80.0
Y_coordinate= 14.00
Z_coordinate= -2.50
所需的方向变化图像 2
更详细地表示所需方向变化的图像 3
最佳答案
通过数据文件中的点进行插值并不容易。我建议设计 B 样条曲线来在平面 1 和 2、平面 6 和 7 之间插入点。平面 2 和平面 6、平面 7 和平面 10 之间的空间看起来非常线性:
clear
filename = 'datafile.txt';
A = importdata(filename);
vertices = A.data(2:end);
vertices = reshape(vertices, 12, [])';
vx = vertices(:, 1:3:10);
vy = vertices(:,2:3:11);
vz = vertices(:,3:3:12);
figure; patch(vx',vy',vz',1); axis equal;
没有简单的方法可以进行此类插值,因为您希望确保沿曲线至少具有 C1 连续性以避免出现任何尖锐边缘。 B 样条曲线在这里可能很有用,但如果您不熟悉它,则很难对其进行编程。幸运的是,我从事一个需要曲面和曲线拟合的项目,并且我手头有代码:
function [x,y,z] = bspline(u, ctrlp, k, knots)
U = bspbasis(u, numel(ctrlp(:,1)), k, knots);
x=U*ctrlp(:,1);
y=U*ctrlp(:,2);
z=U*ctrlp(:,3);
end
function U = bspbasis(u, nctrlp, K, knots)
nu = numel(u);
umax = max(u);
index = 1:nctrlp;
% preallocating variables
U = zeros(nu,nctrlp);
N = zeros(nctrlp+1,K);
% Calculate the denominators for basis functions (k>2). -may be useful when
% the size of point data is substantial, so the calculation is not repeated.
d1 = zeros(nctrlp,K);
d2 = d1;
for m=2:K
d1(:,m) = knots(index+m-1) - knots(index);
d2(:,m) = knots(index+m) - knots(index+1);
end
knots = knots(:);
knots1 = knots(1:nctrlp+1);
knots2 = knots(2:nctrlp+2);
knotSize = size(knots1);
knotc1 = knots(nctrlp+1);
knotc2 = knots(nctrlp+2);
for ui = 1:nu
% k = 1
u_ = u(ui)*ones(knotSize);
NA = u_>=knots1 & u_<knots2;
if u(ui) == umax && knotc1 == umax && knotc2 == umax
NA(1:nctrlp+1) = 0;
NA(end-1,1) = 1;
end
N(:,1) = NA;
% k > 2
for k = 2:K
p1 = (u(ui) - knots(index)) ./ d1(:,k) .* N(index,k-1);
p1(isnan(p1)) = 0;
p2 = (knots(index+k) - u(ui)) ./ d2(:,k) .* N(index+1,k-1);
p2(isnan(p2)) = 0;
N(index,k) = p1 + p2;
end
U(ui,:)=N(1:end-1,k);
end
end
如果你想理解上面的代码,可以阅读B-spline Wikipedia 。 Youtube 上也有很多教程和互动工具如this one .
下面的代码将三阶 B 样条曲线拟合到四组角顶点中的每一个。
u = linspace(0,1,500);
k = 3;
for i = 1:4
ishift = (i-1) * 3 + 1;
p = vertices(:,ishift:ishift+2);
ctrlp = [p(1,:); [0 0 0]; p(2:3,:); p(5:6,:); zeros(2,3); p(7,:); p(8,:)];
ctrlp(2,:) = 5*ctrlp(3,:) - 4*ctrlp(4,:);
ctrlp(7,:) = 2*ctrlp(6,:) - ctrlp(5,:);
ctrlp(8,:) = 4*ctrlp(9,:) - 3*ctrlp(10,:);
knots = getknots(ctrlp, k);
[x_,y_,z_] = bspline(u, ctrlp, k, knots);
x(:,i) = [p(:,1); x_];
y(:,i) = [p(:,2); y_];
z(:,i) = [p(:,3); z_];
[~,I] = sort(x(:,i));
x(:,i) = x(I,i);
y(:,i) = y(I,i);
z(:,i) = z(I,i);
end
c = repmat(1:numel(x)/4,4,1)';
xx=[x;flipud(x(:,[2,3,4,1]))];
yy=[y;flipud(y(:,[2,3,4,1]))];
zz=[z;flipud(z(:,[2,3,4,1]))];
cc=[c;flipud(c)];
figure; patch(xx,yy,zz,cc);
结果是平滑的放样表面:
我想向您解释代码是如何工作的,但在我挣扎了一个小时后,我放弃了......相反,我在下面提供了一些关键点的摘要。
总而言之,使用以下符号:C1、C2、...、C10 是 B 样条曲线的控制点,V1、V2、...、V10 是用于计算 B 样条曲线的顶点样条曲线。下图显示了用于计算第一条 B 样条曲线的控制点和顶点。
u
中的值数量确定最终曲线上的点数。C1 = V1
和C10 = V10
.C2 - V2 = d*(V2-V3)
和C3 = V2
.C3 = V2; C4 = V3; C5 = V5; C6 = V6
.C7-V6 = d*(V6-V5)
.C8-V7 = d*(V7-V8); C9 = V7;
.C10 = V10
和C9 = V7
,曲线经过V8和V9。getknots
getknots
功能:
function knots = getknots(ctrlp, k)
d = sqrt(sum(diff(ctrlp).^2, 2));
ds = cumsum(d)./sum(d);
knots = [zeros(k,1); ds(k-1:end); ones(k,1)];
end
bspline
的多合一代码方法:
clear
filename = 'datafile.txt';
A = importdata(filename);
vertices = A.data(2:end);
vertices = reshape(vertices, 12, [])';
u = linspace(0,1,500);
k = 3;
for i = 1:4
ishift = (i-1) * 3 + 1;
p = vertices(:,ishift:ishift+2);
ctrlp = [p(1,:); [0 0 0]; p(2:3,:); p(5:6,:); zeros(2,3); p(7,:); p(8,:)];
ctrlp(2,:) = 5*ctrlp(3,:) - 4*ctrlp(4,:);
ctrlp(7,:) = 2*ctrlp(6,:) - ctrlp(5,:);
ctrlp(8,:) = 4*ctrlp(9,:) - 3*ctrlp(10,:);
knots = getknots(ctrlp, k);
[x_,y_,z_] = bspline(u, ctrlp, k, knots);
x(:,i) = [p(:,1); x_];
y(:,i) = [p(:,2); y_];
z(:,i) = [p(:,3); z_];
[~,I] = sort(x(:,i));
x(:,i) = x(I,i);
y(:,i) = y(I,i);
z(:,i) = z(I,i);
end
c = repmat(1:numel(x)/4,4,1)';
xx=[x;flipud(x(:,[2,3,4,1]))];
yy=[y;flipud(y(:,[2,3,4,1]))];
zz=[z;flipud(z(:,[2,3,4,1]))];
cc=[c;flipud(c)];
figure; patch(xx,yy,zz,cc);
function [x,y,z] = bspline(u, ctrlp, k, knots)
U = bspbasis(u, numel(ctrlp(:,1)), k, knots);
x=U*ctrlp(:,1);
y=U*ctrlp(:,2);
z=U*ctrlp(:,3);
end
function U = bspbasis(u, nctrlp, K, knots)
nu = numel(u);
umax = max(u);
index = 1:nctrlp;
% preallocating variables
U = zeros(nu,nctrlp);
N = zeros(nctrlp+1,K);
% Calculate the denominators for basis functions (k>2). -may be useful when
% the size of point data is substantial, so the calculation is not repeated.
d1 = zeros(nctrlp,K);
d2 = d1;
for m=2:K
d1(:,m) = knots(index+m-1) - knots(index);
d2(:,m) = knots(index+m) - knots(index+1);
end
knots = knots(:);
knots1 = knots(1:nctrlp+1);
knots2 = knots(2:nctrlp+2);
knotSize = size(knots1);
knotc1 = knots(nctrlp+1);
knotc2 = knots(nctrlp+2);
for ui = 1:nu
% k = 1
u_ = u(ui)*ones(knotSize);
NA = u_>=knots1 & u_<knots2;
if u(ui) == umax && knotc1 == umax && knotc2 == umax
NA(1:nctrlp+1) = 0;
NA(end-1,1) = 1;
end
N(:,1) = NA;
% k > 2
for k = 2:K
p1 = (u(ui) - knots(index)) ./ d1(:,k) .* N(index,k-1);
p1(isnan(p1)) = 0;
p2 = (knots(index+k) - u(ui)) ./ d2(:,k) .* N(index+1,k-1);
p2(isnan(p2)) = 0;
N(index,k) = p1 + p2;
end
U(ui,:)=N(1:end-1,k);
end
end
function knots = getknots(ctrlp, k)
d = sqrt(sum(diff(ctrlp).^2, 2));
ds = cumsum(d)./sum(d);
knots = [zeros(k,1); ds(k-1:end); ones(k,1)];
end
关于matlab - 如何在 MATLAB 中使用矩形放样以创建灵活的 3D 封闭管道?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55852401/
我有以下几行代码: using XXX.PAD.PaidServices; using YYY= XXX.PAD.PaidServices.Judet; //// uncomment below fo
我正在寻找一种方法,让 LAN 中的客户端无需任何配置即可找到我的服务器应用程序的所有实例。我不想自己破解某些东西,而是想使用现有的解决方案。就个人而言,我需要用 Python 完成它,但我很乐意听到
我的“问题”或“挑战”有很多问题。但它们都不符合我的需求。好的,我开始了: 我想要一个保存可变属性的数据库。现在我将它们作为列名“硬编码”到数据库中(参见图片)。请参阅“颜色”和“尺寸”。但是如果我想
我正在为我的一个 friend 创建一个网站。我们得到了这些布局,我已经放了一个灵活的背景,可以缩放到当前的浏览器大小。但是放置在背景上的图标需要在缩放窗口时保持相对位置。意味着如果我调整窗口大小,让
案例 通常,您会使用 cellForRowAtIndexPath 委托(delegate)方法来设置单元格。单元格的信息集对于单元格的绘制方式和大小非常重要。 不幸的是,heightForRowAtI
我试图让下面的 div 变得灵活 div { min-width: 500px; max-width: 1000px; width:100%; height: 400px; margin-left:1
我在单元测试方面遇到问题。当我运行测试时,它以 "No tests found" 结束。我正在使用 AppCode 和 Quick/Nimble 框架进行单元测试,但它在 XCode 中也不起作用。
问之前,请理解我的英语不好。 我在 servlet 编程中使用 Class.forName(...) 类。当我访问 servlet 时,我从数据库中获得一行详细的 Controller 信息,指示要使
我创建了一个cron job在 GAE 灵活环境中,每 15 分钟自动运行一次。 但是在创建每个实例时,是否会为每个实例复制相同的 cron 作业?我对此不太确定。 最佳答案 不,不会为每个实例复制
div A 灵活且固定(位于窗口顶部),具有高 z-index,因此下方的元素可以在滚动时从下方通过。 div B 位于 div A 下方,我希望它“粘”在 div A 的底部,因为在调整窗口大小时高
我是 Quick/Nimble 的新手,所以我尝试了一个简单的单元测试: import Quick import Nimble class DarkSkyTests: QuickSpec {
我创建了一个演示。关于表格单元格的灵 active ,我需要一些帮助。 我有一些表格单元格,它们的宽度应该是固定的。 但单元格由标签组成,标签可以是长文本,也可以是短文本。 基于此标签,表格单元格应该
我非常熟悉在代码中需要“水平带”的网站 - 即使他们的内容固定在 960 像素以内,他们的背景也会向左和向右“延伸”。 我知道如何做这些,如果它们只有一种颜色,或者我可以用作背景的一张图片。 最近一位
我在自己编写的网站(无框架或 CMS)上使用 Cloudflare Flexible SSL。一切正常,现在我想在整个网站上使用 HTTPS。我在 Apache Web 服务器上使用 PHP。 我想知
我有这个 Java 接口(interface): public interface Box { public void open(); public void close(); } 这个接
所以我有一个“主要”功能系统,现在可以作为 CMS 使用:用户进入编辑器并从四个模板中选择一个。在模板中,他们单击可以添加图像、文本或两者的部分。 我有一个预览屏幕,可以向他们展示他们正在制作的东西,
下面的 HTML/CSS/Javascript (jQuery) 代码显示了 #makes 选择框。选择一个选项会显示带有相关选项的 #models 选择框。 #makes 选择框偏离中心,#mode
我正在使用固定高度的图像来填充具有渐变颜色的 div,方法如下:背景:透明 url(green_bg.gif) repeat-x scroll 0 0; 但是它只填充一个等于图像高度的高度。根据其中的
我的系统的 GUI 在 1366 X 768 分辨率下运行良好。当它以不同的分辨率显示时,我需要并排滚动,而它不应该这样。此外,当我尝试在 chrome 中按 ctr+- 时,div 和部分变得困惑。
我正在尝试在 google app engine 灵活环境中使用 python 编写日志。 我想使用默认的 python 日志记录库并使用处理程序进行日志记录。这是我的代码: import loggi
我是一名优秀的程序员,十分优秀!