讨论 --- 写了一个根据日照生成边界的vb脚本(悬赏10分)

[复制链接]
跳转到指定楼层
34607 qiancy88 发表于 2009-11-18 10:28:07 楼主
本帖最后由 wudi1212 于 2009-11-18 23:03 编辑

结果没成功 求高手帮忙看看错在哪里……

思路是先在后面的房子前定一个面,把面分成21*21的格点,在大寒日对每个点每十分钟做一次投影。看投影在后面的房子的窗台轮廓线的南面还是北面。如果在南面的时间于2小时,就把那个点向南移1米,再做一次判断,直到超过2小时以上。

代码如下:
  Sub RunScript(ByVal pts As List(Of On3dPoint), ByVal srfProject As OnSurface, ByVal crvClosest As OnCurve)

'输入:21*21的点,后面房子的窗台所在平面,后面房子的窗台轮廓线


    Dim sunVector As New List(Of On3dVector)
    Dim startH As Integer = 8
    Dim endH As Integer = 16
    Dim startT As Integer = startH * 60
    Dim endT As Integer = endH * 60
    Dim stepT As Integer = 10
    Dim sunDirection As New List(Of On3dVector)
    Dim SolarTime As Integer
    Dim dblTemp,sunh,sunA As Double
    Const pi As Double = 3.1415926
    Const Latitude As Double = 39.13
    Const SolarLatitude As Double = -23.45
    Dim list As New List(Of On3dVector)
    Dim GoodPts As New List(Of On3dPoint)



'得到大寒日8点到16点太阳入射的方向的向量 ,时间间隔10分钟  
    For MinuteID As Integer = startT To endT Step stepT
      SolarTime = 15.0 * ((MinuteID - 12 * 60.0) / 60.0)
      dblTemp = Sin(Latitude / 180 * pi) * Sin(SolarLatitude / 180 * pi) + Cos(Latitude / 180 * pi) * Cos(SolarLatitude / 180 * pi) * Cos(SolarTime / 180 * pi)
      If dblTemp >= -1 And dblTemp <= 1 Then
        Sunh = Asin(dblTemp)
        If Sunh > 0 Then 'ensure the sun is above the ground
          dbltemp = Cos(SolarLatitude / 180 * pi) * Sin(SolarTime / 180 * pi) / Cos(Sunh)
          If dblTemp >= -1 And dblTemp <= 1 Then
            SunA = Asin(dbltemp)
            SunA = SunA * (-1) + 3 * pi / 2
            Dim v As New On3dVector(cos(SunA), sin(SunA), tan(Sunh))
            sunVector.Add(v)
          End If
        End If
      End If
    Next
  


用do……loop循环移动点
    For i As Integer=0 To pts.Count - 1
      Dim blnGood As Boolean
      Do While blnGood = False
        '自定了一个函数isGoodPoint判断改点是否满足日照
        blnGood = isGoodPoint(sunVector, pts(i), srfProject, crvClosest)
        print(blnGood)
        pts(i).y = pts(i).y - 1
      Loop
      GoodPts.add(pts(i))
    Next
    A = GoodPts
  End Sub
'从调试来看好像程序把所有的移动的命令都算在第一个点上了,以至于第一个点移动了730米,其他的点一个都没动……

#Region "Additional methods and Type declarations"
  '自定函数isGoodPoint
  Function isGoodPoint(ByRef listVector As list(Of On3dVector), ByRef pt As On3dPoint, ByRef srf As OnSurface, ByRef crv As OnCurve)As Boolean
    Dim good As Integer = 0
    Dim isgood As Boolean
    For j As Integer =0 To listVector.count - 1
      Dim pt2 As New On3dPoint(pt.x - listVector(j).x * 1000, pt.y - listVector(j).y * 1000, pt.z - listVector(j).z * 1000)
      Dim line As New OnLine(pt, pt2)
      Dim t As Double
      Dim mm As New ArrayOnX_EVENT
      Dim tt As Double = line.IntersectSurface(srf, mm)   
      Dim ProjectPt As New On3dPoint(line.PointAt(tt))
      crv.GetClosestPoint(projectPt, t)
      Dim ClosePt As New On3dPoint (crv.PointAt(t))
      If projectPt.y < closePt.y Then
        good = good + 1
      End If   
    Next
    If good / 6 > 2 Then
      isgood = True
    Else
      isgood = False
    End If
    Return isgood
  End Function
   
  
#End Region



多谢
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
关于大陆地区Rhino原厂培训中心
wudi1212 发表于 2009-11-18 23:02:26
2
本帖最后由 wudi1212 于 2009-11-18 23:15 编辑

不好意思 爱莫能助 vb.net 还不是很熟悉
不过帮你弄了下加分悬赏 希望有朋友可以解答
panhao1 发表于 2009-11-28 15:18:27
3
感觉你的思路不好 对于复杂的形体 还是要做一下预计算 不能直接求
我以前用rs写过一些类似的
还没整成.net脚本
我qq29347213
panhao1 发表于 2009-11-28 15:21:04
4
不过要看下你的形体 要是有图就好了
morphosis 发表于 2009-12-20 13:21:55
5
楼主继续阿,我们都在等着阿。加油~~~
wudi1212 发表于 2009-12-20 15:41:42
6
从Grasshopper3d 上面找到的一张图 应该有些借鉴意义 作者公布了他的VB代码
Solar Radiation Ecotect Script
morphosis 发表于 2009-12-22 00:11:49
7
好啊,支持~~~。牛人赶快继续完成吧,我们翘首以待。高喊加油~~~
zetter 发表于 2010-4-12 19:02:34
8
顶楼主 最近也在这方面努力
您需要登录后才可以回帖 登录 | 注册成为会员

本版积分规则