On 10/07/2016 at 16:28, xxxxxxxx wrote:
In a 2 poly object. That code works if you manually move the points in poly[1].
But if you move poly[1] using joints. The result of angle_deg is always 180.
I'm curious how are you getting that code to work when poly[1] is animated by a joint?
This is how I've done it by multiplying the poly's points by the joint's matrix.
Are you doing it a different way?
import c4d,math
def main() :
obj = op.GetObject()
polys = obj.GetAllPolygons()
points= obj.GetAllPoints()
poly1 = polys[0]
poly2 = polys[1]
#The joint that is moving poly[1]
joint = doc.SearchObject("Joint.2")
mg = joint.GetMg()
a1,b1,c1 = points[poly1.a], points[poly1.b], points[poly1.c]
norm1 = (b1 - a1).Cross(c1 - a1).GetNormalized()
center1 = (a1+b1+c1)*.3333
a2,b2,c2 = points[poly2.a] * mg, points[poly2.b] * mg, points[poly2.c] * mg
norm2 = (b2 - a2).Cross(c2 - a2).GetNormalized()
center2 = (a2+b2+c2)*.3333
v2 = (center2-center1).GetNormalized()
conc = v2.Dot(norm1)
angle_rad = c4d.utils.GetAngle(norm1,norm2)
angle_deg = 180-angle_rad*180.0/math.pi
if conc < 0:
angle_deg = 360 - angle_deg
print angle_deg
-ScottA