modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
98 stars 42 forks source link

What is fillPattern=FillPattern.Sphere on Rectangle or Polygon? #1826

Open modelica-trac-importer opened 5 years ago

modelica-trac-importer commented 5 years ago

Modified by dietmarw on 9 Nov 2015 14:17 UTC How should a rectangle/polygon with fillPattern=FillPattern.Sphere be drawn? Currently tools behave different here.

See attached test model.


Reported by dietmarw on 9 Nov 2015 14:09 UTC How should a rectangle/polygon with fillPattern=FillPattern.Spheree be drawn? Currently tools behave different here.

See attached test model.


Migrated-From: https://trac.modelica.org/Modelica/ticket/1826

modelica-trac-importer commented 5 years ago

Comment by dietmarw on 9 Nov 2015 14:17 UTC Three examples from how it looks in the tools I have available:

[[Image(ticket1826-dymola.png)]]

Dymola2016
[[Image(ticket1826-omedit.png)]]

OMEdit v1.9.3
[[Image(ticket1826-simx.png,)]]

SimulationX 3.7.1
modelica-trac-importer commented 5 years ago

Comment by hansolsson on 9 Nov 2015 14:25 UTC The subject says "Rectangle or Polygon", but all of these are Polygons and not Rectangles. In MSL I believe there are gradients for Rectangles but not for Polygons.

However, I agree that both of them should be defined (possibly saying that it is removed).

modelica-trac-importer commented 5 years ago

Comment by stefanv on 9 Nov 2015 15:34 UTC MapleSim:

Image

modelica-trac-importer commented 5 years ago

Comment by henrikt on 9 Nov 2015 15:59 UTC SystemModeler:

Image

modelica-trac-importer commented 5 years ago

Comment by pharman on 9 Nov 2015 16:01 UTC ESI-Xplorer:

Image

modelica-trac-importer commented 5 years ago

Comment by hansolsson on 9 Nov 2015 16:02 UTC Replying to [comment:3 stefanv]:

MapleSim:

Image

Was this the exact same model?

The reason I ask is that the red (=lineColor) border is missing on the ones to the right, and missing lineColor will also mess up the gradient since it should go from line-color to fill-color.

[And I'm aware that Dymola currently by design does not support gradients for polygons.]

A separate issue is that it would be good to have use-cases for this: I can see that MSL uses fill-pattern for Rectangles, and looking at them I see why - but what is the corresponding use-case for Polygons?

modelica-trac-importer commented 5 years ago

Comment by stefanv on 9 Nov 2015 16:40 UTC Replying to [comment:6 hansolsson]:

Was this the exact same model?

The reason I ask is that the red (=lineColor) border is missing on the ones to the right.

Yes, that's a bug we just discovered (and fixed).

modelica-trac-importer commented 5 years ago

Comment by msasena on 9 Nov 2015 18:17 UTC This is how we interpret the graphics with the current beta version of LMS Amesim 15: Image

modelica-trac-importer commented 5 years ago

Comment by beutlich on 16 Nov 2015 20:49 UTC Questions from my side that need to be answered:

modelica-trac-importer commented 5 years ago

Comment by hansolsson on 18 Nov 2015 09:06 UTC Replying to [comment:9 beutlich]:

Questions from my side that need to be answered: * Radius of sphere or cylinder * Center of sphere * Linear color gradient or other

Before doing this I think we should consider what is the use for these gradients.

A rectangle with vertical/horizontal cylinder gradient can be used as 3d-looking cylinder. An ellipse/circle with spherical gradient can be used as 3d-looking ellipsoid/sphere. In those cases all of the questions above are indirectly answered, and they are used in MSL.

So, can we find corresponding use-cases for general polygons? An example is Modelica.Mechanics.Rotational.Components.Gearbox where the icon has two cones with head missing that ideally should have a cylinder-gradient.

However, it would not be close to the images above, but have a gradient between the midline of the cone and the edge of the cone (getting steeper towards the top of the cone). That seems useful - but I don't know if we can generalize that to general polygons in a good way. (Convex laterally symmetric polygons seems possible.)

In MSL we also have a rectangle with spherical gradient in Modelica.Mechanics.Translational.Components.Mass - I don't know the intent, but it could be due to my ignorance. [I later found out that the 3d-look is the intersection of a vertical and horizontal cylinder.]

Conclusion: If we can find use-cases for gradients of polygons I believe we should try to make gradients fit the use-cases. Otherwise I would propose we deprecate most of these cases and only keep cylinders for Rectangle and sphere for Ellipse; and focus on documenting that.

modelica-trac-importer commented 5 years ago

Comment by beutlich on 18 Nov 2015 20:00 UTC Oops, I was expecting a short answer here, like take the center of gravity as center of the circle, choose the largest radius such that the circle will fit inside the polygon and choose a linear color gradient. This would do it, for example.

modelica-trac-importer commented 5 years ago

Comment by stefanv on 18 Nov 2015 20:06 UTC I think that the short answer you were expecting is wrong, as that would hardly look spherical as the name implies it should.

"For every complex problem there is an answer that is clear, simple, and wrong." -- H. L. Mencken

modelica-trac-importer commented 5 years ago

Comment by beutlich on 18 Nov 2015 20:15 UTC How's MapleSim doing it then?

modelica-trac-importer commented 5 years ago

Comment by stefanv on 18 Nov 2015 21:10 UTC Replying to [comment:13 beutlich]:

How's MapleSim doing it then?

See comment 6 above (we had a bug wherein the border colour wasn't being used, which we've already fixed in-house). But I think our spheres look spherical, and our cylinders cylindrical.

modelica-trac-importer commented 5 years ago

Comment by beutlich on 18 Nov 2015 21:17 UTC Sure, I know the picture but what is the algorithmic part behind the spherical looking sphere and cylindrical looking cylinder?

modelica-trac-importer commented 5 years ago

Comment by stefanv on 20 Nov 2015 20:09 UTC First we create a linear colour gradient table, which for the purposes of this discussion, we'll pretend is indexed by a real number between 0 and 1. The index into this table for the cylindrical shading is then sqrt(1-d2) where d ranges from 0 to 1 and represents the distance from the central axis. For the spherical shading, the index is 1-d (which is conical, not spherical).

modelica-trac-importer commented 5 years ago

Comment by stefanv on 20 Nov 2015 21:40 UTC It seems that all the tools (that attempt shading at all) draw the spherical fill pattern as conical, and all the tools except MapleSim draw the cylindrical fill pattern as prismatic.

We decided to experiment here with using actual spherical shading (i.e. sqrt(1-d2) where d is the distance from the centre). The top two images use the current conical shading, and the bottom two use spherical shading:

Image

So the question then is, which oneshould be used?

modelica-trac-importer commented 5 years ago

Comment by dietmarw on 20 Nov 2015 22:33 UTC As some decision help I thought to attach the "ball" from the Modelica logo. I would say its shape (despite the shadow effect of course) is closer to the second row variant.

[[Image(ModelicaBall.png)]]
modelica-trac-importer commented 5 years ago

Comment by jmattsson on 21 Nov 2015 10:36 UTC Replying to [comment:17 stefanv]:

So the question then is, which oneshould be used?

This is a detail I think can be up to each tool, as the difference is small enough to still give the same "look and feel" of the icons.

That said, I think the spherical ones look better than the conical ones.

modelica-trac-importer commented 5 years ago

Comment by hansolsson on 23 Nov 2015 11:17 UTC Replying to [comment:16 stefanv]:

First we create a linear colour gradient table, which for the purposes of this discussion, we'll pretend is indexed by a real number between 0 and 1. The index into this table for the cylindrical shading is then sqrt(1-d2) where d ranges from 0 to 1 and represents the distance from the central axis. For the spherical shading, the index is 1-d (which is conical, not spherical).

I think the (1-d) gradient looks ok, but I don't agree with calling it conical. The spherical/conical names above are based on false-coloring according to z-values, which doesn't seem like the right approach.

As indicated above let us consider an actual 3d-object (sphere/cylinder). For the lighting one normally uses a combination of ambient, diffuse and specular light; and the computations are based on the normal in each point. (Can't remember the exact formula at the moment; but see http://glprogramming.com/red/chapter05.html#name7 )

The normal's projection in the z-direction is (1-d) for a sphere/cylinder (I believe); but constant for a cone pointing in the z-direction.

Updated: so if we are wearing a headlight and looking at a sphere it should be ambient+diffuse*(1-d)+specular*(1-d)s for some reasonable value for s, or just set specular=0, and then ambient correspond to lineColor and diffuse to fillColor-lineColor.

If we want to consider more general polygons one example would be a cone seen from the side - and in that case false-coloring based on z-values will be quite off for the top of the cone; whereas the normal-approach will capture that.

modelica-trac-importer commented 5 years ago

Comment by stefanv on 26 Feb 2016 22:05 UTC Another question is whether the fill pattern is rotated or not. If I fill with the "Forward" pattern, and specify a rotation of 45 degrees, does it look like the "Vertical" pattern? Likewise, does a "HorizontalCylinder" filled rectangle, rotated 45 degrees, look like a diagonal cylinder, or a rotated rectangle curved around the horizontal axis?

modelica-trac-importer commented 5 years ago

Comment by hansolsson on 7 Mar 2016 15:19 UTC Replying to [comment:21 stefanv]:

Another question is whether the fill pattern is rotated or not. If I fill with the "Forward" pattern, and specify a rotation of 45 degrees, does it look like the "Vertical" pattern? Likewise, does a "HorizontalCylinder" filled rectangle, rotated 45 degrees, look like a diagonal cylinder, or a rotated rectangle curved around the horizontal axis?

Clarified behavior in Dymola:

henrikt-ma commented 3 years ago

Reopening: The least we can do here is to forbid the unclear cases until we can agree how they should render.