I am new to SymPy and I would like to create a SymPy-Triangle from three dimensional points e.g. to obtain its surface area:
import numpy as np
import sympy as sp
p1 = np.array([1,1,1])
p2 = np.array([3,2,2])
p3 = np.array([2,3,4])
It is not possible to create a Triangle object like that:
triangle = sp.Triangle(p1,p2,p3,) #Won't work: Nonzero coordinates cannot be removed.
In a next move I created a plane on the xy-plane with z=0 and projected the original points of the triangle onto that plane:
plane = sp.Plane((0,0,0), (1,0,0), (0,1,0))
p1_proj = plane.projection(p1) # Point3D(1,1,0)
p2_proj = plane.projection(p2) # Point3D(2,2,0)
p3_proj = plane.projection(p3) # Point3D(3,3,0)
triangle_proj = sp.Triangle(p1_proj, p2_proj, p3_proj,)
area_proj = triangle_proj.area # 3/2
Now I do not get an error anymore, because all the z-components of the projected points are zero, but the triangle is now obviously also distorted and thus its area has changed:
area_original = 0.5 * np.linalg.norm( np.cross((p2-p1),(p3-p1),) ) # 2.96
Does anyone know how the transform the points of my triangle, so that all the z-coordinates become zero? Maybe even using SymPy (but that’s not necessity).
Thank you so much, spatial imagination is not one of my strengths!
Best regards
Martin
Triangle
can be constructed by indicating the length of each side of the triangle so instead of looking for a transform you can just calculate the length of each side as defined in the Plane:
>>> a,b,c=map(Point,([1,1,1],[3,2,2],[2,3,4]))
>>> Triangle(sss=(a.distance(b),b.distance(c),c.distance(a)))
Triangle(Point2D(0, 0), Point2D(sqrt(6), 0), Point2D(7*sqrt(6)/6, sqrt(210)/6))
>>> _.area
sqrt(35)/2
>>> _.n()
2.95803989154981
The transformation of a plane to the xy plane is discussed here.