createShape
Description
Examples
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 object, specified as a sim3d.Actor
object.
Example: actor = sim3d.Actor()
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'
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)