cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

How to fill a quadrilateral with color ?

lvl107
20-Turquoise

How to fill a quadrilateral with color ?

Hello Everyone.
From :
Fill_Quadrilateral.png
How to fill the ( convex, concave, complex ) quadrilateral with color ?
Thanks in advance for your time and help.
Best Regards.
Loi.

1 ACCEPTED SOLUTION

Accepted Solutions
ttokoro
20-Turquoise
(To:lvl107)

18 REPLIES 18
ttokoro
20-Turquoise
(To:lvl107)

Use old hatch function to fill the area.

image.pngimage.png

ttokoro
20-Turquoise
(To:ttokoro)

Use 3D plot

image.pngimage.png

lvl107
20-Turquoise
(To:ttokoro)

1.PNG

5.png

4.png

lvl107
20-Turquoise
(To:ttokoro)

Many thanks, Ttokoro. 🙄 🤔 I got your hint of convex quadrilateral.

1.PNG  

   But I have still stuck in the concave and complex quadrilateral.

2.PNG

  Best Regards.

 

ttokoro
20-Turquoise
(To:lvl107)

Change B and D.

image.pngimage.pngimage.pngimage.pngimage.png

lvl107
20-Turquoise
(To:ttokoro)

  Thanks again, Ttokoro. 😊 😊 🤔  Now, I think that we would need changing the intersection points "by hand" : ( Is there a way exchanging between intersection points with codes (program function) for three of case of convex, concave, and complex quadrilaterals. ? )

3.PNG

The last case : complex quadrilateral.

Regards.

ttokoro
20-Turquoise
(To:lvl107)

After be named all points and lines, stacking Hatch function may be programable.

image.png

image.png

ttokoro
20-Turquoise
(To:ttokoro)

P is all points [x y] data. data is 3 points numbers to make triangle and stack all triangles.HatchAll fill the triangles.

 

image.pngimage.pngimage.pngimage.pngimage.png

lvl107
20-Turquoise
(To:lvl107)

  and another similar query :

Fill_3_CloseShape.png

  Fill 3 of the close-shape ?

 

ttokoro
20-Turquoise
(To:lvl107)

image.pngimage.png

Can you attache also a Mathcad Prime file worksheet? it is not pretty visible in the image you have posted

lvl107
20-Turquoise
(To:lvl107)

and :

Fill_3_CloseShape (2).png

Many thanks for your last post, Ttokoro. 😊 🤔

Best Regards.

   Loi.

Werner_E
24-Ruby V
(To:lvl107)

Very easy to do. Only slight changes are necessary

Werner_E_0-1690311819803.png

Generally the approach with the boolean function which Prof. Birkeland had chosen is quite flexible and powerful, yet easy to use.

For example

Werner_E_1-1690311939515.png

Would be significantly more work to achieve with other methods, I guess.

 

Here another, simpler example, which could easily also created using the "classic" Hatch/Fill function with its vertical lines

Werner_E_2-1690312679222.png

 

Werner_E
24-Ruby V
(To:lvl107)

IMHO using Prof. Birkeland's functions is much easier and more fun 😉

If you don't want to dig into the details, the very first function Dots() is all you need for a simple fill. Only filling with hatch lines (of arbitrary angle) or with a family of arbitrary curves would need the other functions.

 

Setting up the boolean functions which define the area is more logical and easier as opposed to having to think about intersecting which curves  and  then assemble the areas to be colored from the correct partial areas via stack().

Intersecting the curves was only done for the orange filled area  because of the way I decided it has to look like (and I just notice that in the definition of orange(x,y) we could omit the y<blue(x) part).

 

As seen with the turquoise colored area one benefit of using dots is that we can let the axis ticks and numbers see through as otherwise (seen at the yellow and magenta colored area) the axis are overlaid (this is different from the behaviour in Prime).

You may also chose to change the trace type from "point" to "line" to get kind of a zig-zag fill. I tried but I didn't like it.

Werner_E_0-1690304592892.png

 

lvl107
20-Turquoise
(To:Werner_E)

  Thanks again, Werner. 😊 🤔. I got it :

A.PNG

  Best Regards.

Werner_E
24-Ruby V
(To:lvl107)

Maybe the work of Prof. Birkeland can help, too.

See attachment in this posting: https://community.ptc.com/t5/Mathcad/How-to-fill-the-area-under-the-curve-with-colours/m-p/888943/highlight/true#M207711

 

As you are using real Mathcad you probably are rather interested in the predecessor for Mathcad 15. Its attached here.

 

BTW, four lines do NOT define a unique quadrilateral as you can see here:

Werner_E_0-1690076732435.png

Better you provide the vertices and keep in mind, that the order in which you provide the points matter!

 

To use Prof. Birkeland's functions you will have to provide a boolean function which determines if a point is inside the to-be-hatched area or not.

I vaguely remember that I provided that kind of "pointInPolygon" function in an older thread for a different purpose, but it seems that I did not keep a copy and I could not find that thread with a quick search.

Birkeland provides three functions to fill shapes in his worksheet, Dots, Hatch and Shade.

Dots is the most simple one and can be used to fill arbitrary polygons with an orthogonal dot grid. Varying the number of dots and their size you may also simulate a plain fill.

Werner_E_1-1690082440035.png

After quite some reformatting it worked in Prime, too, but unfortunately Prime is limited concerning the number of different line widths (=point sizes in Prime) and the number of points its can plot while respecting the set line width, The center plot with about 17000 points won't work OK because of this limitation and the number of dots had to be reduced.

Werner_E_2-1690082859414.png

 

 

 

lvl107
20-Turquoise
(To:Werner_E)

   Many thanks for your hints. Werner. 😊 🤔 :

Werner_E_1-1690082440035.png

---

6.png

 

Top Tags