查看单个帖子
旧 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自动化论坛(仅游客可见)