如何在WPF中绘制凹角矩形?

时间:2022-08-11 23:44:49

How can I draw a concave corner rectangle in WPF?

如何在WPF中绘制凹角矩形?

3 个解决方案

#1


3  

You can create this by Path Operation under Expression blend (Menu - Object-> Path operations) I have created a Path by subtracting four ellipse against a rectangle.

您可以通过表达式混合下的路径操作创建它(菜单 - 对象 - >路径操作)我通过对矩形减去四个椭圆来创建路径。

the Path.Data for a concave rectangle is given below, @Kent Fredric logic in the previous answer will be helpful to implement one.

下面给出了凹面矩形的Path.Data,上一个答案中的@Kent Fredric逻辑将有助于实现一个。

alt text http://img87.imageshack.us/img87/4539/concaverectny1.jpg

alt text http://img87.imageshack.us/img87/4539/concaverectny1.jpg

M17.200002,0L120.4,0 120.4,2.3066998E-06C120.4,6.7378696,128.10079,12.200001,137.60001,12.200001L137.60001,85.400003C128.10077,85.400003,120.4,90.862138,120.4,97.6L17.200002,97.6C17.200002,90.862151,9.4993697,85.400003,0,85.400003L0,12.199999C9.4993663,12.200015,17.200002,6.7378725,17.200002,0z

See the blog post here http://jobijoy.blogspot.com/2008/11/concave-cornered-rectangle-blend-tip.html

请参阅此处的博客文章http://jobijoy.blogspot.com/2008/11/concave-cornered-rectangle-blend-tip.html

Another way to get this is to create a WPF Custom Shape like bellow

另一种方法是创建一个像波纹管一样的WPF自定义形状

public class ConcaveRectangle:System.Windows.Shapes.Shape

#2


2  

do you mean a rectangle with concave corners?, ie: 
     ____________________
    |                    |
  __|                    |__
 |                          |
 |                          |
 |                          |
 |__                      __|
    |                    |
    |____________________|

Given a rectangle of dimension w x h with corner radius r There are 4 corners:

给定一个尺寸为w x h且角半径为r的矩形有4个角:

A :  0,0
B :  w,0
C :  w,h
D :  0,h

There is an implicit minimum size of

隐含的最小尺寸为

w = 2r
h = 2r

There are 4 Circle Centers, A,B,C,D

有4个圆心,A,B,C,D

And there's thus a grid of edge points:

因此有一个边缘点网格:

(0,0)--(0+r,0)---(w-r,0)---(w,0)
|                              |
(0,0+r)                  (w,0+r)
|                              |
|                              |
(0,h-r)                  (w,h-r)
|                              |
(0,h)--(0+r,h)---(w-r,h)---(w,h)

Then its merely a case of computing the arc from one point to another.

然后它仅仅是从一点到另一点计算弧的情况。

#3


0  

I should point out that if it's concave, the four sides aren't both identical and straight; thus it's not a rectangle. But I digress.

我应该指出,如果它是凹的,四边不是相同和直的;因此它不是一个矩形。但我离题了。

#1


3  

You can create this by Path Operation under Expression blend (Menu - Object-> Path operations) I have created a Path by subtracting four ellipse against a rectangle.

您可以通过表达式混合下的路径操作创建它(菜单 - 对象 - >路径操作)我通过对矩形减去四个椭圆来创建路径。

the Path.Data for a concave rectangle is given below, @Kent Fredric logic in the previous answer will be helpful to implement one.

下面给出了凹面矩形的Path.Data,上一个答案中的@Kent Fredric逻辑将有助于实现一个。

alt text http://img87.imageshack.us/img87/4539/concaverectny1.jpg

alt text http://img87.imageshack.us/img87/4539/concaverectny1.jpg

M17.200002,0L120.4,0 120.4,2.3066998E-06C120.4,6.7378696,128.10079,12.200001,137.60001,12.200001L137.60001,85.400003C128.10077,85.400003,120.4,90.862138,120.4,97.6L17.200002,97.6C17.200002,90.862151,9.4993697,85.400003,0,85.400003L0,12.199999C9.4993663,12.200015,17.200002,6.7378725,17.200002,0z

See the blog post here http://jobijoy.blogspot.com/2008/11/concave-cornered-rectangle-blend-tip.html

请参阅此处的博客文章http://jobijoy.blogspot.com/2008/11/concave-cornered-rectangle-blend-tip.html

Another way to get this is to create a WPF Custom Shape like bellow

另一种方法是创建一个像波纹管一样的WPF自定义形状

public class ConcaveRectangle:System.Windows.Shapes.Shape

#2


2  

do you mean a rectangle with concave corners?, ie: 
     ____________________
    |                    |
  __|                    |__
 |                          |
 |                          |
 |                          |
 |__                      __|
    |                    |
    |____________________|

Given a rectangle of dimension w x h with corner radius r There are 4 corners:

给定一个尺寸为w x h且角半径为r的矩形有4个角:

A :  0,0
B :  w,0
C :  w,h
D :  0,h

There is an implicit minimum size of

隐含的最小尺寸为

w = 2r
h = 2r

There are 4 Circle Centers, A,B,C,D

有4个圆心,A,B,C,D

And there's thus a grid of edge points:

因此有一个边缘点网格:

(0,0)--(0+r,0)---(w-r,0)---(w,0)
|                              |
(0,0+r)                  (w,0+r)
|                              |
|                              |
(0,h-r)                  (w,h-r)
|                              |
(0,h)--(0+r,h)---(w-r,h)---(w,h)

Then its merely a case of computing the arc from one point to another.

然后它仅仅是从一点到另一点计算弧的情况。

#3


0  

I should point out that if it's concave, the four sides aren't both identical and straight; thus it's not a rectangle. But I digress.

我应该指出,如果它是凹的,四边不是相同和直的;因此它不是一个矩形。但我离题了。