尝试旋转和变换 SVG 路径 - 我需要三角学计算吗?
我正在尝试使用鼠标 SVG 路径进行操作,该路径代表电子电阻器的符号。该符号需要使用“引线”末端进行操作(如果您可以想象真实的电阻器);因此,我试图实现拖动第一个点周围(第二个点仍然存在),并且当在新坐标上拖动第一个点时,路径的所有点都按比例表现。
尝试分组,尝试使用三角函数......所以代码如下:
`<g id="r" > <!-- R - group for symbol of electronics resistor -->
<path d="M 200 20 v80 h30 v150 h-60 v-150 h30 m 0 150 v80 "
fill="none" stroke="blue" stroke-width="5" />
<circle cx="200" cy="20" r="10"
fill="blue" />
<circle cx="200" cy="330" r="10"
fill="blue"/>
</g>`
请帮忙。
I'm trying to manipulate with mouse SVG path which represents symbol of electronics resistor. This symbol requires manipulation with end of the "leads" (if you can picture real resistor); therefore I am trying to achieve draging 1st point arround (2nd is still there) and to all points of path to behave proportionally in when drag the 1st point on new coordinates.
Try to group, try with trigonometry functions...so code is like:
`<g id="r" > <!-- R - group for symbol of electronics resistor -->
<path d="M 200 20 v80 h30 v150 h-60 v-150 h30 m 0 150 v80 "
fill="none" stroke="blue" stroke-width="5" />
<circle cx="200" cy="20" r="10"
fill="blue" />
<circle cx="200" cy="330" r="10"
fill="blue"/>
</g>`
Please, help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经大致做了你想要的: http://dl.dropbox.com/u/169269/resistor .svg
单击并拖动电阻器以将其缩放并旋转到鼠标位置。在此版本中,线条粗细和圆圈也会缩放,但避免这种情况应该不会太困难。
它确实需要三角学和变换。关键部分是拖动功能,我在以下位置对其进行了更详细的解释: http:// www.petercollingridge.co.uk/interactive-svg-components/draggable-svg-element
请注意,此代码假设电阻器长 310 像素并旋转约 (200, 100)。缩放和旋转变换以 (0,0) 为中心进行工作,因此您应该在 (0,0) 处绘制静态点的电阻,然后将其平移到您想要的位置。
I think I've made roughly what you want: http://dl.dropbox.com/u/169269/resistor.svg
Click and drag on the resistor to scale and rotate it to that mouse position. In this version, the line thickness and circles also scale, but it shouldn't be too difficult to avoid that.
It does require trigonometry and transformations. The key part is the drag function, which I explain in more detail at: http://www.petercollingridge.co.uk/interactive-svg-components/draggable-svg-element
Note that this code assumes the resistor is 310 pixels long and rotating about (200, 100). Scaling and rotation transformations work centred on (0,0), so you should draw the resistor with the static point at (0,0) and then translate it to where you want.