当前位置:网站首页>Basics | draw arcs in the physics engine
Basics | draw arcs in the physics engine
2022-06-29 16:35:00 【User 1097444】
author |zzbozheng
original text |http://imweb.io/topic/5959aee62536e43f14da1a68
Because of the demand , To use quarter arcs in the physics engine , Let's see how to draw a quarter arc in the physics engine ,
Draw arcs in the physics engine
Generally speaking , Physical engines provide general drawing methods , such as :circle( round )、polygon( Irregular polygon )、rectangle( rectangular ) Isograph , But if you need to draw flexible and irregular figures , Then we need to use svg Support for . Let's discuss how to realize quarter arc : Let's take a look svg Medium path Label available parameters :
Instructions | Parameters | explain |
---|---|---|
M | x y | Move the brush to the point (x,y) |
L | x y | The brush draws a line segment from the current point to the point (x,y) |
H | x | The brush draws a horizontal line segment from the current point to the point (x,y0) |
V | y | The brush draws a vertical line segment from the current point to the point (x0,y) |
A | rx ry x-axis-rotation large-arc-flag sweep-flag x y | The brush draws an arc from the current point to the point (x,y) |
C | x1 y1, x2 y2, x y | The brush draws a cubic Bezier curve from the current point to the point (x,y) |
S | x2 y2, x y | A special version of the cubic Bezier curve ( Omit the first control point ) |
Q | x1 y1, x y | Draw a quadratic Bezier curve to a point (x,y) |
T | x y | A special version of the quadratic Bezier curve ( Omit control points ) |
Z | No parameter | Draw a closed graph , If d Property does not specify Z command , Then draw a line segment , Instead of closed graphics . |
You can see path The instructions of the tag are very rich and powerful , If you need to draw an arc , Then you need to use A The instructions are most appropriate . Draw arc command :A rx ry x-axis-rotation large-arc-flag sweep-flag x y
It can be understood as :
- Draw a paragraph to (x,y) Ellipse arc of . The shape of an elliptical arc x, y The radii of the axes are rx,ry.
- The ellipse is relative to x Shaft rotation x-axis-rotation degree .
- large-arc=0 Indicates that the arc is less than 180 degree ,large-arc=1 It means that the arc is greater than 180 degree .
- sweep=0 Indicates that the arc rotates counterclockwise , sweep=1 Indicates that the arc rotates in time .
It's more abstract , Let's take a look at the figure below
:
If you want to draw a quarter arc in the lower left corner :
The results of :
- M80 80 Represents from the canvas x:80 y:80 Start drawing
- A45 45 Representing an ellipse x The radius length is 45px ,y The radius length is 45px.( It's all about 45, So it's a circle )
- 0 0 0 first 0 Means relative to x The shaft does not rotate , the second 0 Indicates that only the arc less than 180 The period of , Third 0 It means the part drawn counterclockwise
- 125 125 Represents the end of the arc .
- L 128 80 Z Means draw a straight line to x: 128 y: 80,Z Indicates the automatic closing path .
It looks like a convex arc from the appearance , So if you need a concave arc, how do you achieve it ? First, you need to have such a picture in your mind or on paper :
We can use the above example to make some modifications , The arc is still the arc we need , But the connection points of straight lines are different , Then we just need to modify the connection point
If you want a small arc in the upper right corner ? In fact, you need a small clockwise arc , So put the code above sweep-flag Part to 1 That's all right. .
SVG Conversion to the physical engine
Because what we use here is matter.js So you can go through matter.js Methods provided Svg.pathToVertices Come and take svg Convert to canvas route .
Scan the QR code below the code ,
Follow more front-end dry goods articles at any time !
▼
WeChat :IMWebTech
边栏推荐
- 高级性能测试工程师面试必问十大问题
- What's the difference between isempty and isblank? Half of the people can't answer it?
- 美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三
- The rooster Electronic Society graphical programming real questions and answers analysis of the scratch grade test level 1 June 2022
- It's also a test. Why do others get an annual salary of 30w+?
- 基础 | 在物理引擎中画圆弧
- MySQL基础——多表查询
- 『计组』CPU 如何区分指令和数据
- After reading the complete code
- 对于产业互联网的认识,直接关系着我们究竟会以怎样的心态来看待它
猜你喜欢
MATLAB给数据加噪声/扰动
apache atlas断点查看
The latest agenda of dtcc2022 China database technology conference was released
Sophon base 3.1 launches mlops function to provide wings for enterprise AI capability operation
加速智能驾驶项目落地?你还缺一套真值测评系统
STM32按键消抖——入门状态机思维
为防止被00后整顿,一公司招聘要求员工不能起诉公司
隐私计算助力数据的安全流通与共享
穩定幣風險狀况:USDT 和 USDC 安全嗎?
Sophon Base 3.1 推出MLOps功能,为企业AI能力运营插上翅膀
随机推荐
After 3 years of testing experience, do you know the state transition method for use case design?
分片信息调哪个参数呢?用的是MySQLsource stream api,不是table api
After studying this series of notes about software testing, it is a "bonus" to enter the factory
【无标题】
美国芯片再遭重击,Intel或将被台积电击败而沦落至全球第三
Huaxia Fund: sharing of digital transformation practice achievements in the fund industry
apache atlas断点查看
实践 | 移动端图片上传旋转、压缩的解决方案
Locust performance pressure test tool
Redis布隆过滤器和布谷鸟过滤器
In order to prevent being rectified after 00, a company requires employees not to sue the company
[proteus simulation] progressive increase / decrease of nixie tube with flashing blanking display
A simple but scalable feature normalization method
Key sprite fighting monsters - window binding skill
水球图-利用动态波纹展示百分比
Telnet+ftp to control and upgrade the equipment
数学知识:求组合数 II—求组合数
[proteus simulation] nixie tube +4x4 keyboard matrix key simple calculator
MySQL cdc jobmanager 中存了哪些比较耗内存的数据呢?
Comprehensive analysis of Seata distributed transaction at and XA