createShape
Description
Examples
Build Actor from 3D Graphic Primitives Using MATLAB
This example shows how to build an actor from a 3D graphic primitive using MATLAB®.
You can use the sim3d.World
and sim3d.Actor
objects to create a 3D environment with an actor. First, you create a 3D environment and an actor object. Next, you build the actor from 3D graphic primitives, including box, cylinder, plane, and sphere using the createShape
function. Then, you add the actor to the world, transform the actor, and set a view in the scene. Finally, you view the actor in the Simulation 3D Viewer window.
To build an actor from a 3D graphic primitive using Simulink®, see Build Actor from 3D Graphic Primitives Using Simulink.
Create 3D Environment
Create a world object.
world = sim3d.World();
Create Actor
Instantiate an actor object named Cylinder
. You can use any name for the actor.
actor = sim3d.Actor(ActorName='Cylinder');
Build a cylinder shape for the actor object and specify its size. Specify a color. Add the actor object to the world.
createShape(actor,'cylinder',[0.5 0.5 .75]);
actor.Color = [1 0 1];
add(world,actor);
Set Actor Transformation
Use the actor object translation, rotation, and scale properties to orient the actor relative to the world origin.
actor.Translation = [0 0 0]; actor.Rotation = [0 0 0]; actor.Scale = [1 1 1];
Set Viewer Window Point of View
If you do not create a viewport, then the default view is set and you can use the keyboard shortcuts and mouse controls to navigate in the Simulation 3D Viewer window.
For this example, use the createViewport
function to create a viewport.
viewport = createViewport(world,Translation=[-4.5 0 1]);
Run Animation
Run a simulation set for 10
seconds with a sample time of 0.02
seconds.
sampletime = 0.02; stoptime = 10; run(world,sampletime,stoptime)
Delete World
Delete the world object.
delete(world)
Input Arguments
actor
— Actor class where new geometry is created
sim3d.Actor
object
Actor class where the new geometry is created, specified as a sim3d.Actor
object.
type
— Name of 3D graphic primitive
'arrow'
| 'box'
| 'cone'
| 'cylinder'
| 'checker'
| 'icosphere'
| 'plane'
| 'prism'
| 'pyramid'
| 'revolution'
| 'sphere'
| 'surf'
| 'terrain'
| 'torus'
| 'triad'
| 'tube'
Name of 3D graphic primitive, specified as one of these values:
'arrow'
'box'
'cone'
'cylinder'
'checker'
'icosphere'
'plane'
'prism'
'pyramid'
'revolution'
'sphere'
'surf'
'terrain'
'torus'
'triad'
'tube'
inputspec
— Optional parameters of each shape type
details of shape type
Optional parameters of each shape type, specified as details of the shape type.
The table lists the optional parameters for each shape type.
Type | Optional Parameters | Example |
---|---|---|
|
| createShape(ActObj,'arrow', [2 4 2], 16, 2) |
|
| createShape(ActObj,'box', [2 2 2]) |
|
| createShape(ActObj,'cone', [2 3 4], 12, 2) |
|
| createShape(ActObj,'cylinder', [2 3 4], 12, 2) |
|
| createShape(ActObj,'checker', [4 4 1], [4 4], [1 0 0], [0 0
1]) |
|
| createShape(ActObj,'icosphere', [3 3 3], 2, 3) |
|
Note Depending on the
| createShape(ActObj,'plane', [3 0 3], 2, true) |
|
| createShape(ActObj,'prism', [2 2 2], 0.25, 2) |
|
| createShape(ActObj,'pyramid', [3 3 3], 2) |
|
| createShape(ActObj,'revolution', [1 1; 2 3; 5 2], 24, true,
true) |
|
| createShape(ActObj,'sphere', [2 2 2], 16, 2) |
|
| createShape(ActObj,'surf', [1 2 3; 1 2 3; 1 2 3], [1 1 1; 2 2 2; 3
3 3], [1 2 3; 4 5 6; 1 2 3]) |
|
| createShape(ActObj,'terrain', [4 4 4], [1 0 1 0;1 0 1 0], 2,
true); |
|
| createShape(ActObj,'torus', [4 4 4], 2, 16, 1) |
|
| createShape(ActObj,'triad', [2 1 2], 20, 0.2) |
|
| createShape(ActObj,'tube', [2 2 2], 0.75, 26, 1) |
Version History
Introduced in R2022b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)