几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » ObjectARX(VB.NET/C#)
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-19, 09:23 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】.net编程求出四个端点组成的两条直线的相交点

.net编程求出四个端点组成的两条直线的相交点
www.dimcax.com
.net编程求出四个端点组成的两条直线的相交点
'''求出两直线的交点
public function inters(byval p1 as point3d, byval p2 as point3d, byval p3 as point3d, byval p4 as point3d, optional byval type as boolean = true) as point3d
if math.ieeeremainder(math.abs(getangle(p1, p2) - getangle(p3, p4)), math.pi) = 0 then
return nothing
end if
dim a1, a2, b1, b2, c1, c2, c3, x1, x2, y1, y2, x, y, z as double
dim lp as point3d
x1 = p1.x
y1 = p1.y
x2 = p3.x
y2 = p3.y
a1 = p2.y - p1.y
b1 = p2.x - p1.x
a2 = p4.y - p3.y
b2 = p4.x - p3.x
c1 = a1 / b1
c2 = a2 / b2
c3 = (p2.z - p1.z) / b1
x = (y2 - c2 * x2 + c1 * x1 - y1) / (c1 - c2)
if b1 = 0 then
x = p1.x
c1 = 1.0e+20
c3 = c1
end if
if b2 = 0 then
x = p3.x
c2 = 1.0e+20
end if
y = c1 * (x - x1) + y1
z = c3 * (x - x1) - p1.z
if x - x1 = 0 then
y = c2 * (x - x2) + y2
end if
lp = new point3d(x, y, z)
dim d1, d2, d3, d4, od1, od2, od3, od4 as double
d1 = p1.distanceto(p2)
d3 = p3.distanceto(p4)
od1 = lp.distanceto(p1)
od2 = lp.distanceto(p2)
od3 = lp.distanceto(p3)
od4 = lp.distanceto(p4)
if type then
return lp
elseif od1 <= d1 and od2 <= d1 and od3 <= d3 and od4 <= d3 then
return lp
else
return nothing
end if
end function
望各位多指点。我没发现只好自已编了一个,但我怕出毛病。
[此贴子已经被作者于
lisp vba arx .net开发都会一点。可惜都不精。希望和大家共同学习进步。
'''求出两直线的交点
public function inters(byval p1 as point3d, byval p2 as point3d, byval p3 as point3d, byval p4 as point3d, optional byval type as boolean = true) as point3d
if math.ieeeremainder(math.abs(getangle(p1, p2) - getangle(p3, p4)), math.pi) = 0 then
return nothing
end if
dim a1, a2, b1, b2, c1, c2, c3, x1, x2, y1, y2, x, y, z as double
dim lp as point3d
x1 = p1.x
y1 = p1.y
x2 = p3.x
y2 = p3.y
a1 = p2.y - p1.y
b1 = p2.x - p1.x
a2 = p4.y - p3.y
b2 = p4.x - p3.x
c1 = a1 / b1
c2 = a2 / b2
c3 = (p2.z - p1.z) / b1
x = (y2 - c2 * x2 + c1 * x1 - y1) / (c1 - c2)
if b1 = 0 then
x = p1.x
c1 = 1.0e+20
c3 = c1
end if
if b2 = 0 then
x = p3.x
c2 = 1.0e+20
end if
y = c1 * (x - x1) + y1
z = c3 * (x - x1) - p1.z
if x - x1 = 0 then
y = c2 * (x - x2) + y2
end if
lp = new point3d(x, y, z)
dim d1, d2, d3, d4, od1, od2, od3, od4 as double
d1 = p1.distanceto(p2)
d3 = p3.distanceto(p4)
od1 = lp.distanceto(p1)
od2 = lp.distanceto(p2)
od3 = lp.distanceto(p3)
od4 = lp.distanceto(p4)
if type then
return lp
elseif od1 <= d1 and od2 <= d1 and od3 <= d3 and od4 <= d3 then
return lp
else
return nothing
end if
end function

自己编的,请大家评评。
lisp vba arx .net开发都会一点。可惜都不精。希望和大家共同学习进步。
望大侠指点。我对自己编的这个东东不放心。呵……如果程序有就太好了。
lisp vba arx .net开发都会一点。可惜都不精。希望和大家共同学习进步。
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 05:47 PM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多