MATLAB 板


LINE

各位大大,小弟用Matlab转档案 目前是用Matlab吃进来 stl 档案然後在用圆座标去取上面的vertex 三角形的点。 下面的范例是小弟尝试用 (phi,theta,r)圆座标去取点,其中的phi和theta 为固定几个角度,所以这边 是要取r 的值出来,最後再去描点(3dplot)再看结果。 小弟方法分两个步骤, 第一个就是patch.face 规定的三个点围成的平面和我所要描的 (phi,theta,r)对於圆心(0 0 0 )拉出来的线求交点。 第二个就是用这个交点作线性规划,找交点位於三点围成的三角形之类,才是我判别 点是在vertex 的平面上面,这样就可以确定 r 值了。 第二个线性规划上面,我是用交点 vs.三角形分开为一条线 和一个点作,如下图右边线为三角形的两个点所成,然後交点只要在三角形内,则d1>d2 以此类推,我只要作三次都符合,就可以知道交点在这个face 内了。 d1 | 三角形上之点。-----------| d2 | 交点。-----| | 当然小弟是觉得这个方法很烂,目前抓的效果也没很好 不知道有没有更聪明的办法或是现成的func来确定3D下, "点是否在一个三角形内哩?" 感谢 !! (如果有人想try我这版本的code,请在跟我讲哩,在给您详细pattern之类的) input_pat = strcat('./data/',pattern,'.stl'); fv = stlread(input_pat); %% Render % The model is rendered with a PATCH graphics object. We also add some dynamic % lighting, and adjust the material properties to change the specular % highlighting. patch(fv,'FaceColor', [0.8 0.8 1.0], ... 'EdgeColor', 'none', ... 'FaceLighting', 'gouraud', ... 'AmbientStrength', 0.15); % Add a camera light, and tone down the specular highlighting camlight('headlight'); material('dull'); % Fix the axes scaling, and set a nice view angle axis('image'); %view([0 90]); view([-175 55]); size_pts = size(fv.vertices); number_points = size_pts(1); angle_C = zeros(1,number_points); angle_G = zeros(1,number_points); intensity = zeros(1,number_points); % All points here cart_points = fv.vertices; % All triangle series here face = fv.faces; %====================== % Debug figure,plot3(cart_points(1:end,1),cart_points(1:end,2),cart_points(1:end,3)); %====================== for i = 1:number_points [angle_C(i),angle_G(i),intensity(i)] = cart2sph(cart_points(i,1),cart_points(i,2),cart_points(i,3)); end %========= % Shift the Angle to fir IES format %============================== angle_C = angle_C*180/pi+180; angle_G = angle_G*180/pi+90; % G value: vertical angle, theta G_index = [0.00 2.00 4.00 6.00 8.00 10.00 12.00 14.00 16.00 18.00... 20.00 22.00 24.00 26.00 28.00 30.00 32.00 34.00 36.00 38.00... 40.00 42.00 44.00 46.00 48.00 50.00 52.00 54.00 56.00 58.00... 60.00 62.00 64.00 66.00 68.00 70.00 72.00 74.00 76.00 78.00... 80.00 82.00 84.00 86.00 88.00 90.00 92.00 94.00 96.00 98.00... 100.00 102.00 104.00 106.00 108.00 110.00 112.00 114.00 116.00 118.00... 120.00 122.00 124.00 126.00 128.00 130.00 132.00 134.00 136.00 138.00... 140.00 142.00 144.00 146.00 148.00 150.00 152.00 154.00 156.00 158.00... 160.00 162.00 164.00 166.00 168.00 170.00 172.00 174.00 176.00 178.00... 180.00]; % C value:horizontal angle, phi C_index = [90.00 105.00 120.00 135.00... 150.00 165.00 180.00 195.00 210 225.00 240.00 255.00 270.00 285.00... 300.00 315.00 330.00 345.00 0.00 15.00 30.00 45.00 60.00 75.00 90]; length_C = size(C_index); length_G = size(G_index); length_output = length_C(2)*length_G(2); output_intensity = zeros(1,length_output); intesity_test = 1; length_intensity = size(intesity_test); test_points = zeros(3,length_intensity(2)); test_points1 = zeros(3,200); tb_int1 = zeros(1,200); tb_int = zeros(length_intensity(2),number_points/3); %========================= % Debug sampled_x = zeros(1,number_points); sampled_y = zeros(1,number_points); sampled_z= zeros(1,number_points); inter_point = zeros(3,number_points/3); dist_point = zeros(1,number_points/3); thd_dist = 0.01; for i = 1:length_C(2) for j = 1:length_G(2) tmp_angle_C = (C_index(i) - 180)*pi/180; tmp_angle_G = (G_index(j) - 90)*pi/180; [test_points(1,intesity_test),test_points(2,intesity_test),test_points(3,intesity_test)] = ... sph2cart(tmp_angle_C,tmp_angle_G,intesity_test); for k =1:number_points/3 inter_point(:,k) = plane_line_intersection(cart_points(face(k,1),:),cart_points(face(k,2),:),cart_points(face(k,3),:),... 0,0,0,test_points(1),test_points(2),test_points(3)); % Linear Program a_flag_direction = (round(test_points(1,intesity_test))*round(inter_point(1,k))>=0)&&... (round(test_points(2,intesity_test))*round(inter_point(2,k))>=0)&&... (round(test_points(3,intesity_test))*round(inter_point(3,k))>=0); d_ori1 = dist(inter_point(:,k)',cart_points(face(k,1),:),cart_points(face(k,2),:)); d_ver1 = dist(cart_points(face(k,3),:),cart_points(face(k,1),:),cart_points(face(k,2),:)); d_ori2 = dist(inter_point(:,k)',cart_points(face(k,2),:),cart_points(face(k,3),:)); d_ver2 = dist(cart_points(face(k,1),:),cart_points(face(k,2),:),cart_points(face(k,3),:)); d_ori3 = dist(inter_point(:,k)',cart_points(face(k,1),:),cart_points(face(k,3),:)); d_ver3 = dist(cart_points(face(k,2),:),cart_points(face(k,1),:),cart_points(face(k,3),:)); if(d_ori1<(d_ver1-thd_dist))&&(d_ori2<(d_ver2-thd_dist))&&(d_ori3<(d_ver3-thd_dist))&&a_flag_direction %disp(['k=',int2str(k),',[x y z]= ',int2str(inter_point(:,k)')]); %disp(['P1= ',int2str(cart_points(face(k,1),:)),', P2= ',int2str(cart_points(face(k,2),:)),', P3= ',int2str(cart_points(face(k,3),:))]); dist_point(k) = sum(d_ori1+d_ori2+d_ori3); %disp(['dist_total = ',int2str(dist_point(k))]); end end [B1,index1] = max(dist_point); [tmp_C,tmp_G,tmp_intensity] = cart2sph(inter_point(1,index1),inter_point(2,index1),inter_point(3,index1)); output_intensity((i-1)*length_G(2)+j)= tmp_intensity; sampled_x((i-1)*length_G(2)+j)= inter_point(1,index1); sampled_y((i-1)*length_G(2)+j)= inter_point(2,index1); sampled_z((i-1)*length_G(2)+j)= inter_point(3,index1); end end figure,... plot3(sampled_x,sampled_y,sampled_z); --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.17.237
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/MATLAB/M.1400574240.A.C17.html
1F:→ YoursEver:改用barycentric coor.;直接看交点是不是落在三角形内. 05/20 17:04
2F:→ binjon:感谢楼上,2014新func ? 我在试一下 !! 05/21 11:15
3F:→ YoursEver:http://ppt.cc/If7G 05/21 11:33







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Boy-Girl站内搜寻

TOP