Hi Bera,
Assuming that your axes could be at an angle from the default x-y axes, you can follow the following approach to plot the required grid pattern:
- Plot the original axes (Red and Blue line)
x_range = linspace(-10, 10, 400);
2. Generate parallel lines at a fixed distance away from the original lines. For this, use a method that shifts the lines by adjusting the intercept (b).
for i = -num_lines:num_lines
y_shift = m1 * x_range + b_shift;
plot(x_range, y_shift, 'LineStyle', '-', 'Color', [0.8, 0.5, 0.5]);
for i = -num_lines:num_lines
y_shift = m2 * x_range + b_shift;
plot(x_range, y_shift, 'LineStyle', '-', 'Color', [0.5, 0.5, 0.8]);
3. Finally, to find intersections between two sets of lines, you can use the fact that at the intersection, the
values are equal. So, (
), which can be solved for
. These can then be plotted. for i = -num_lines:num_lines
for j = -num_lines:num_lines
x_intersect = (b2_shift - b1_shift) / (m1 - m2);
y_intersect = m1 * x_intersect + b1_shift;
viscircles([x_intersect, y_intersect], 0.2, 'Color', 'k', 'LineWidth', 0.5);
The final graphs might look like:
Hope this helps!