Hi
I am trying to create a PlaneSurface from a rectangular light. I can get the light position and direction, but how do you get the rotation pls? Rhinocommon.
Thanks
Hi
I am trying to create a PlaneSurface from a rectangular light. I can get the light position and direction, but how do you get the rotation pls? Rhinocommon.
Thanks
I think something like the following will work:
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetRectLightCorners(light):
oPt=light.Geometry.Location
len=light.Geometry.Length
wid=light.Geometry.Width
return [oPt,oPt+len,oPt+len+wid,oPt+wid]
def TestGetLightCornersFunction():
lightID=rs.GetObject("Get light",256,True)
lightObj=sc.doc.Objects.Find(lightID)
corners=GetRectLightCorners(lightObj)
print corners
TestGetLightCornersFunction()
(from the corners you can get the plane surface, of course)
–Mitch
Here is a way to get the plane surface directly… I haven’t yet figured out how to properly orient the surface normal to the light direction vector though (if that’s important to you)… --Mitch
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetRectLightPlaneSrf(light):
oPt=light.Geometry.Location
len=light.Geometry.Length
wid=light.Geometry.Width
plane=Rhino.Geometry.Plane(oPt,len,wid)
u_interval = Rhino.Geometry.Interval(0, len.Length)
v_interval = Rhino.Geometry.Interval(0, wid.Length)
return Rhino.Geometry.PlaneSurface(plane, u_interval, v_interval)
def TestGetRectLightPlaneSrfFunction():
lightID=rs.GetObject("Get light",256,True)
if not rs.IsRectangularLight(lightID): return
lightObj=sc.doc.Objects.Find(lightID)
srf=GetRectLightPlaneSrf(lightObj)
sc.doc.Objects.AddSurface(srf)
sc.doc.Views.Redraw()
TestGetRectLightPlaneSrfFunction()
And finally… the plane surface normal will face in the direction of the light…
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def GetRectLightPlaneSrf(light):
oPt=light.Geometry.Location
len=light.Geometry.Length
wid=light.Geometry.Width
dir=light.Geometry.Direction
plane=Rhino.Geometry.Plane(oPt,len,wid)
u_interval = Rhino.Geometry.Interval(0, len.Length)
v_interval = Rhino.Geometry.Interval(0, wid.Length)
ang=Rhino.Geometry.Vector3d.VectorAngle(dir,plane.Normal)
if ang < sc.doc.ModelAngleToleranceDegrees:
return Rhino.Geometry.PlaneSurface(plane, u_interval, v_interval)
else:
plane.Flip()
return Rhino.Geometry.PlaneSurface(plane, v_interval, u_interval)
return planeSrf
def TestGetRectLightPlaneSrfFunction():
lightID=rs.GetObject("Get light",256,True)
if not rs.IsRectangularLight(lightID): return
lightObj=sc.doc.Objects.Find(lightID)
srf=GetRectLightPlaneSrf(lightObj)
sc.doc.Objects.AddSurface(srf)
sc.doc.Views.Redraw()
TestGetRectLightPlaneSrfFunction()
This works perfectly. Thank you,