You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SymPy does not work with 3D objects other than Point, Plane and LinearEntity. Any such objects can be rotated into the x-y plane and queried there for any properties of interest.
>>fromhttps://github.com/sympy/sympy/issues/24936importRotationMatrix>>>fromsympyimport*>>>pts= [(0, 0, 0), (1, 2, 3), (4, 4, 5)]
>>>p=Plane(*pts)
>>>eqs=list(RotationMatrix(x=x,y=y)*Matrix(p.normal_vector))
>>>sol=solve(eqs[:2])[0] # want normal to be parallel to Z axis so x and y components are 0>>>r=RotationMatrix(x=sol[x],y=sol[y])
>>>t=Triangle(*[list(r*Matrix(i))[:2] foriinpts])
>>>t.area# negative because of orientation of points-sqrt(69)/2
Putting this all together to return a helper function for dealing with any xy-point of interest might be like this:
defzPolygon(*pts):
"""return co-planar points in Polygon and function that will rotate any point in the xy-plane into the plane containing the pts as originally passed Examples ======== >>> pts = [(0, 0, 0), (1, 2, 3), (4, 4, 5)] >>> t, f = zPolygon(*pts) # aTriangle is returned from 3 pts >>> f(t.centroid) Point3D(5/3, 2, 8/3) """assertnotall(len(i) ==2foriinpts), 'use Polygon for 2D points'assertlen(pts) >2, 'Point and Lines can be 3D'p=Plane(*pts[:3])
assertall(iinpforiinpts[3:])
eqs=list(RotationMatrix(x=x,y=y)*Matrix(p.normal_vector))
# normal to be parallel to z axis: x and y components are 0sol=solve(eqs[:2])[0]
r=RotationMatrix(x=sol[x],y=sol[y])
g=Polygon(*[list(r*Matrix(i))[:2] foriinpts])
_r=RotationMatrix(y=-sol[y],x=-sol[x])
returng, lambdapt: Point(*_r*Matrix(list(pt)+[0]*(3-len(pt))))
tri=Triangle(Point3D(1,0,0),Point3D(0,1,0),Point3D(0,0,1))
while running this code it shows the following errorThe text was updated successfully, but these errors were encountered: