Skip to content

Commit 5636519

Browse files
committed
Fix issues with arcs.
Adding 360 degrees to the computed theta1 if theta1 is negative and independently doing the same for theta2 is incorrect. For example, if theta1 is negative, but theta2 is positive, then that can result in theta1 being greater than theta2 and give an unintended result, and is inconsistent with the JSXGraph result in this case. What should happen is that 360 be added to theta2 if theta2 is less than or equal to theta1, and theta1 should never be modified. This gives consistent results with the JSXGraph arc in all cases (except the case below, and that is made consistent with the JSXGraph change in this commit). JSXGraph is not capable of drawing a 360 degree arc (i.e., the case that an arc starts and ends at the same point). So if the start and end point are the same, then move the end point back around the circle a tiny amount so that JSXGraph will draw the entire circle.
1 parent 04bfedd commit 5636519

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Plots/JSXGraph.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ sub add_arc {
575575
radiusPoint => { visible => 0 },
576576
);
577577

578+
if ($x2 == $x3 && $y2 == $y3) {
579+
my $theta = atan2($y2 - $y1, $x2 - $x1) + 2 * 3.14159265358979 - 0.0001;
580+
$x3 = $x1 + cos($theta);
581+
$y3 = $y1 + sin($theta);
582+
}
583+
578584
$self->{JS} .= "board.create('arc', [[$x1, $y1], [$x2, $y2], [$x3, $y3]], $arcOptions);" if $arcOptions;
579585
$self->{JS} .= "board.create('arc', [[$x1, $y1], [$x2, $y2], [$x3, $y3]], $fillOptions);" if $fillOptions;
580586
return;

lib/Plots/Tikz.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,7 @@ sub draw {
567567
my $r = sqrt(($x2 - $x1)**2 + ($y2 - $y1)**2);
568568
my $theta1 = 180 * atan2($y2 - $y1, $x2 - $x1) / 3.14159265358979;
569569
my $theta2 = 180 * atan2($y3 - $y1, $x3 - $x1) / 3.14159265358979;
570-
$theta1 += 360 if $theta1 < 0;
571-
$theta2 += 360 if $theta2 < 0;
570+
$theta2 += 360 if $theta2 <= $theta1;
572571
$tikzCode .= $self->draw_on_layer(
573572
"\\draw[name path=$curve_name, $draw_options->[0]] (axis cs:$x2,$y2) "
574573
. "arc[start angle=$theta1, end angle=$theta2, radius = $r];\n",

0 commit comments

Comments
 (0)