def _test_functions(): # test cgpoint_to_rgpoint point = cgpoint_to_rgpoint(cg.Point(1, 2, 3)) if point.Z != 3.0: raise Exception("cgpoint_to_rgpoint failed.") # test cgvector_to_rgvector vector = cgvector_to_rgvector(cg.Vector(5, 1, 9)) if not vector.Unitize(): raise Exception("cgvector_to_rgvector failed") # test cgline_to_rgline line = cgline_to_rgline(cg.Line([1, 2, 3], [3, 2, 1])) if line.Direction != rg.Vector3d(2, 0, -2): raise Exception("cgline_to_rgline failed") # test frame_to_plane plane = cgframe_to_rgplane(cg.Frame([1, 3, -1], [1, 1, 2], [0, 1, 1])) if not isinstance(plane.Normal, rg.Vector3d): raise Exception("cgframe_to_rgplane failed") # matrix_to_rgtransform R = cg.Rotation.from_basis_vectors([1, 2, 0], [2, 1, 3]) if not isinstance(matrix_to_rgtransform(R), rg.Transform): raise Exception("matrix_to_rgtransform failed")
def rgvector_to_cgvector( v, ): # type: (Rhino.Geometry.Vector3d) -> compas.geometry.Vector """Convert :class:`Rhino.Geometry.Vector3d` to :class:`compas.geometry.Vector`. Parameters ---------- v : :class:`Rhino.Geometry.Vector3d` Vector object to convert Returns ------- :class:`compas.geometry.Vector` Resulting vector object """ return cg.Vector(v.X, v.Y, v.Z)
:class:`Rhino.Geometry.Transform` """ rgM = rg.Transform() for i, row in enumerate(M): for j, val in enumerate(row): rgM[i, j] = val return rgM if __name__ == "__main__": # test cgpoint_to_rgpoint point = cgpoint_to_rgpoint(cg.Point(1, 2, 3)) assert point.Z == 3.0 # test cgvector_to_rgvector vector = cgvector_to_rgvector(cg.Vector(5, 1, 9)) assert vector.Unitize() # test cgline_to_rgline line = cgline_to_rgline(cg.Line([1, 2, 3], [3, 2, 1])) assert line.Direction == rg.Vector3d(2, 0, -2) # test frame_to_plane plane = cgframe_to_rgplane(cg.Frame([1, 3, -1], [1, 1, 2], [0, 1, 1])) assert isinstance(plane.Normal, rg.Vector3d) # matrix_to_rgtransform R = cg.Rotation.from_basis_vectors([1, 2, 0], [2, 1, 3]) assert isinstance(matrix_to_rgtransform(R), rg.Transform)
for x in range(dim): vector.append(random.randint(-100, 100)) return vector ### geometry 1 def three_orthonorm_vectors(u, v): v1 = u v2 = u.cross(v) v3 = v2.cross(u) return v1.unitized(), v2.unitized(), v3.unitized() u = cg.Vector(4, 5, -1) v = cg.Vector(2, 3, 5) print(three_orthonorm_vectors(u, v)) ### geometry 2 polygon = [[4, 5, 0], [0, 6, 0], [-3, 2, 0], [-1, 2, 0]] print(cg.area_polygon(polygon)) ### geometry 3i #create arrays of n length array_length = 10 vector_dimension = 3 array_1 = [gen_rand_vector(vector_dimension) for x in range(array_length)] array_2 = [gen_rand_vector(vector_dimension) for x in range(array_length)]