from time import time import numpy as np from gsurface.plotter.mayavi import SurfacePlot, mayavi_plot_surfaces from gsurface.surface import Cylinder, Sphere cyl = Cylinder(R=1.0).translate(np.array([0.0, 0.0, 1.0])) half_sph = Sphere(R=1.0).setlims(u_ul=np.pi) cyl_surf = cyl.build_surface(*cyl.mesh(50, 50)) half_sph_surf = half_sph.build_surface(*half_sph.mesh(50, 50)) a = time() area = cyl.area() b = time() print(cyl, cyl.area(), f"theorical surface = 2*pi {b - a:.3f}ms") print(half_sph, half_sph.area(), "theorical surface = 4*pi/2 = 2*pi (half sphere)") mayavi_plot_surfaces([SurfacePlot(cyl_surf), SurfacePlot(half_sph_surf)])
from gsurface.model import SurfaceGuidedMassSystem, build_s0 from gsurface.advanced.structure import SurfaceGuidedStructureSystem, TriangleStructure, BowStructure, CarStructure, SnakeStructure from gsurface.surface import Sphere, Tore # setup simulation for tore tore = Tore(r=0.5, R=1.0).translate(np.array([3.0, 0.0, 0.0])) tore_sim = SurfaceGuidedMassSystem( surface=tore, s0=build_s0(du0=10.0), m=1.0, forces=[Gravity(1.0, np.array([0.0, 0.0, -9.0])), ViscousFriction(0.5)]) # setup simulation for sphere sphere = Sphere(1.0) sphere_sim = SurfaceGuidedMassSystem( surface=sphere, s0=build_s0(u0=1.5, du0=10.0, v0=1.5), m=1.0, forces=[Gravity(1.0, np.array([0.0, 0.0, 9.0])), ViscousFriction(0.5)]) tore_sim2 = SurfaceGuidedMassSystem( surface=Tore(0.5, 1.0), s0=build_s0(u0=0.0, du0=0.5, v0=1.0, dv0=0.0), m=1.0, forces=[ SpringForce(stiffness=5.0, clip=np.array([0.0, 0.0, 0.0])), Gravity(m=1.0, g=np.array([0.0, 0.0, -2.0])),
from gsurface import SurfaceGuidedMassSystem, SpringForce, LengthedSpringForce, Gravity, AirFriction, ViscousFriction from gsurface.indexes import * from gsurface.surface import Sphere, Plan, Tore import matplotlib.pyplot as plt from mayavi import mlab import numpy as np # model sphere = Sphere(1.0) m = 1.0 g = np.array([-1.0, 0.0, 0.0]) k = 1.0 clip = np.array([0.0, 0.0, 1.0]) system = SurfaceGuidedMassSystem( surface=sphere, s0=np.array([np.pi/2, 1.0, np.pi/2, 0.0]), m=m, forces=[ Gravity(m=m, g=g), SpringForce(stiffness=k, clip=clip), # ViscousFriction(mu=0.2), ] ) # simulate
import numpy as np from scipy.spatial.transform import Rotation from gsurface import SurfaceGuidedMassSystem, build_s0 from gsurface.advanced.structure import TriangleStructure, SurfaceGuidedStructureSystem from gsurface.forces import StaticFieldElectroMagneticForce, SpringForce, ViscousFriction, Gravity, NewtonGravity from gsurface.serialize import save, load from gsurface.surface import Plan, Tore, Sphere, Catenoid filename = "../_tmp/serialized_plan.txt" plan = Plan(1, 2, 3, 1) plan.translate(np.array([1.0, 2.0, 0.0])) sphere = Sphere(0.5).multlims(0.5).translate(np.array([1.0, 2.0, 0.0])).rotate( Rotation.from_rotvec([0.0, 1.0, 2.0]).as_matrix()) tore = Tore() cat = Catenoid() forces = [ StaticFieldElectroMagneticForce(1.0, np.array([1.0, 2.0, 3.0])), SpringForce(), ViscousFriction(), Gravity(), Gravity() + NewtonGravity() ] model1 = SurfaceGuidedMassSystem(surface=sphere, forces=forces, solid=23.0, s0=build_s0(1.0, 2.0, 3.0, 4.0))
import time as timelib from gsurface.forces import Gravity, ViscousFriction from gsurface.forces.interaction import OneSideSpringInteraction from gsurface.imodel import * from gsurface.indexes import Tyi from gsurface.model import build_s0 from gsurface.plotter.mayavi import mlab, mayavi_plot_surfaces, SurfacePlot from gsurface.surface import Sphere, Tore, Plan # objects sphere = Sphere(0.8).translate(np.array([0.0, 0.0, 0.0])) mesh_sphere = sphere.build_surface(*sphere.mesh(50, 50)) tore = Tore(r=0.5, R=2.0).translate(np.array([0.0, 0.0, 0.0])) mesh_tore = tore.build_surface(*tore.mesh(50, 50)) plan_shift = np.array([0.0, 0.0, -1.0]) plan = Plan.from_xz_rotation(np.pi / 2 * 0.1).translate(plan_shift).setlims( v_ll=-4, v_ul=4, u_ll=-4, u_ul=4) mesh_plan = plan.build_surface(*plan.mesh(50, 50)) gravity_vector = np.array([0.0, 0.0, -10.0]) tore_sim = SurfaceGuidedMassSystem(surface=tore, s0=build_s0(v0=np.pi / 2, du0=3.0), m=1.0) sphere_sim = SurfaceGuidedMassSystem( surface=sphere, s0=build_s0(v0=np.pi / 2, dv0=2),
from gsurface.surface import Sphere surface = Sphere() print(surface.check_verbose())