Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add triangle and quadrilateral tools to the graph tool. #1191

Merged

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Feb 8, 2025

These were requested by Robin Cruz in https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8646.

The usage of the new tools is documented in the parserGraphTool.pl macro.

Example problems for testing this are attached.

Quadrilateral.pg.txt
Triangle.pg.txt

@drgrice1 drgrice1 force-pushed the graphtool-triangle-and-quadrilateral branch 9 times, most recently from f17313d to d88fb39 Compare February 11, 2025 12:09
@pstaabp
Copy link
Member

pstaabp commented Feb 11, 2025

The triangle tool worked well.

When I used your sample problem with many different seeds (248, 6775), the correct answer wasn't accepted. Those both had internal crossings, so I thought that might be an issue, but I even hardcoded a simple square and didn't work.

@drgrice1 drgrice1 force-pushed the graphtool-triangle-and-quadrilateral branch from d88fb39 to 0d76db2 Compare February 11, 2025 13:22
@drgrice1
Copy link
Member Author

There was a mistake that I fixed recently that made it so the quadrilateral cmp method wasn't even being called. It should work now.

Copy link
Member

@pstaabp pstaabp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works now. Looks good.

@drgrice1 drgrice1 force-pushed the graphtool-triangle-and-quadrilateral branch from 0d76db2 to 922ee87 Compare February 12, 2025 17:34
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 12, 2025
This was requested by @somiaj in our last developer meeting.

The usage of the new tool is documented in the parserGraphTool.pl
macro.

The "vector" graph object derives from the "line" graph object, and the
"VectorTool" tool derives from the "LineTool" tool.  That saves some
code redundancy.

Note that there will be some minor conflicts with openwebwork#1191 that will need
to be resolved.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 12, 2025
This was requested by @somiaj in our last developer meeting after I told
him that I already had this encoded. I have had it as a custom tool for
a long time now.

The usage of the new tool is documented in the parserGraphTool.pl
macro.

The "vector" graph object derives from the "line" graph object, and the
"VectorTool" tool derives from the "LineTool" tool.  That saves some
code redundancy.

Note that there will be some minor conflicts with openwebwork#1191 that will need
to be resolved.
These were requested by Robin Cruz in
https://webwork.maa.org/moodle/mod/forum/discuss.php?d=8646.

The usage of the new tools is documented in the parserGraphTool.pl
macro.
@drgrice1 drgrice1 force-pushed the graphtool-triangle-and-quadrilateral branch from 922ee87 to e0a3d0c Compare February 25, 2025 21:39
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 25, 2025
This was requested by @somiaj in our last developer meeting after I told
him that I already had this encoded. I have had it as a custom tool for
a long time now.

The usage of the new tool is documented in the parserGraphTool.pl
macro.

The "vector" graph object derives from the "line" graph object, and the
"VectorTool" tool derives from the "LineTool" tool.  That saves some
code redundancy.

Note that there will be some minor conflicts with openwebwork#1191 that will need
to be resolved.
@Alex-Jordan
Copy link
Contributor

What should happen if you use the quadrilateral tool to make a "bad" quadrilateral like in the picture, and then fill? The current behavior is to not respect where the edges cross. Just checking that is what we'd want.

Screenshot 2025-02-25 at 1 52 25 PM

Options:

  1. The way it works now is what we want.
  2. We'd want it to only fill one of the triangles.
  3. It won't let you make a quadrilateral like this because it always plots the convex quadrilateral, no matter the point sequence.

I am not able to think through which option it should be...

@Alex-Jordan
Copy link
Contributor

I notice the tool won't let me make a degenerate quadrilateral (like with three collinear points). This is also something I am wondering about. Could there be an exercise where in the abstract you are asking for a quadrilateral (so you provide this tool) but the answer could be a degenerate one?

Is the question of allowing degenerate quadrilaterals a separate question from allowing "hourglass" quadrilaterals like in my previous post?

@Alex-Jordan
Copy link
Contributor

It won't let you make a quadrilateral like this because it always plots the convex quadrilateral, no matter the point sequence.

I realized that is not an option. I had to remember about non-convex quadrilaterals where specifying four points does not uniquely define the quadrilateral. Like three points in an equilateral triangle with a fourth point at their center.

@drgrice1
Copy link
Member Author

That is how it pretty much how the fill has to work for now. In order to do better it requires rewriting the general graphtool fill code.

Currently there is an assumption that objects are two sided. Basically there are three states a point can satisfy. Either the point is on one side of the object, the other side of the object, or on the object. Basically, the fillCmp method is designed to be like Perl's cmp or <=> operators. It returns -1 for all points on one side of an object, 0 for points on the object, and 1 for all points on the other side of the object. The original design of the fill tool was that it is an inequality fill. It fills the region that satisfies a given inequality (> 0 or < 0) for the equation defining the object, and there was an assumption that the things graphed were curves.

Of course quadrilaterals are not two sided. They can have intersection points which result in three regions as in your example. Furthermore, the inequality fill concept doesn't work with this implementation. In order for the inequality approach to work, something more is needed than the current cmp type approach. See the comment on line 68 of htdocs/js/GraphTool/quadrilateral.js.

As to degeneracy, I went with the design of the existing tools to not allow degeneracy. For example. the line tool does not allow graphing the same point twice. The triangle tool added here also does not allow three collinear points. Note that the "hourglass" quadrilateral is a valid quadrilateral. It is not degenerate, and so it is allowed. Three consecutive collinear vertices are not allowed in a polygon. In general, a vertex is not allowed to be on the line segment between any two other vertices in a polygon. However, two edges of a polygon are allowed to intersect (just not at a vertex). Note that JSXGraph does allow polygons to be degenerate, and this could be changed to allow degeneracy. The code that prevents degeneracy is in the adjustDragPosition method in htdocs/js/GraphTool/quadrilateral.js.

@Alex-Jordan Alex-Jordan merged commit c50623b into openwebwork:develop Feb 25, 2025
3 checks passed
@drgrice1 drgrice1 deleted the graphtool-triangle-and-quadrilateral branch February 25, 2025 23:07
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 25, 2025
This was requested by @somiaj in our last developer meeting after I told
him that I already had this encoded. I have had it as a custom tool for
a long time now.

The usage of the new tool is documented in the parserGraphTool.pl
macro.

The "vector" graph object derives from the "line" graph object, and the
"VectorTool" tool derives from the "LineTool" tool.  That saves some
code redundancy.

Note that there will be some minor conflicts with openwebwork#1191 that will need
to be resolved.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 27, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Feb 27, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Mar 1, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Mar 2, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Mar 3, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
drgrice1 added a commit to drgrice1/pg that referenced this pull request Mar 4, 2025
…point.

This is to fix a comment I placed in the code about filling
quadrilaterals, and the comment made by @Alex-Jordan in
openwebwork#1191 (comment).

The code implemented in openwebwork#1191 fills the entire interior of a
quadrilateral even if it is a crossed quadrilateral (that is a
quadrilateral with two edges that intersect). That is inconsistent with
all of the other graph tool objects in some sense.  To be more
consistent only the region inside the quadrilateral that satisfies the
same inequalities relative to the borders should be filled.  So that is
what this does.

I also was doing some benchmarking of the TikZ fill code used for
generating hardcopy and noticed that some things were rather slow. The
slow down it turns out was using MathObject Reals in computations. There
is no need for the MathObject structure in those computations, so all of
the fill code now uses the perl values instead. It isn't even funny how
much faster computations are with pure perl numbers versus MathObject
Reals. The difference is rather extreme. Performing something like 10000
basic arithmetic operations with MathObject Reals takes more than five
seconds, but with pure perl numbers it takes less than 20 milliseconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants