Geometria

Geometria 2D planoan

Bi puntuen arteko zuzena, beronen luzera eta irudia (<<Graphics`Arrow` -> geziak
marrazteko paketea, Arrow -> geziak, Line -> zuzenak, Point -> puntuak, 
ParametricPlot -> koordenatu parametrikoetan dagoen funtzioaren grafika)

<< Graphics`Arrow`

pt1 = {3, 4};
pt2 = {8, 1};

seg = pt2-pt1

malda[p1_, p2_] := 
      N[(p2[[2]] - p1[[2]])/(p2[[1]] - 
              p1[[1]])]

malda[pt1, pt2]

luzera[p1_]:=N[
        Sqrt[Sum[p1[[i]]^2, {i, 1, Length[p1]}]]]

luzera[pt2 - pt1]

Show[
      Graphics[{Arrow[{0, 0}, seg], {Hue[0.3], 
            Thickness[
              0.008], 
Line[{pt1, pt2}]}, {PointSize[0.02], 
            Hue[0.1], Point[pt1], Point[pt2]}, 
Text[pt1, 
            pt1, {0, -1}, {1, 0}], 
          Text[pt2, 
            pt2, {0, -1}, {1, 0}]}], 
Axes -> 
        True, PlotRange -> All];

ptzuzen[p1_, p2_, t_] := 
      p1 + t*(p2 - p1);

t = -1.5; ptz=ptzuzen[pt1, pt2, t]

Show[{ParametricPlot[
            ptzuzen[pt1, pt2, s], {s, Min[0, t], 
              Max[0, t]}, 
AxesOrigin -> {0, 0}, 
            DisplayFunction -> 
              Identity], 
Graphics[{{Hue[0.3], 
                Thickness[
                  0.01], 
Line[{pt1, pt2}]}, {PointSize[
                  0.02], Hue[0.1], Point[pt1], 
Point[pt2], 
                Point[ptz]}, 
              Text[pt1, pt1, {0, -1}, {1, 0}], 
Text[
                pt2, pt2, {0, -1}, {1, 0}], 
              Text[ptz, 
                ptz, {0, -1}, {1, 0}]}]}, 
Axes -> 
          True, PlotRange -> All, 
        DisplayFunction -> $DisplayFunction];

Bi segmentuen batura, beraien arteko angelua eta beraiek mugatutako paralelogramoaren 
area (angeluaren cosinua -> cos θ = segmentu1.segmentu2/(||segmentu1||·||segmentu21||), 
paralelogramoaren area -> ||segmentu1||·||segmentu21||·sin θ  edo ||segmentu1×segmentu21|| )

<< Calculus`VectorAnalysis`

seg1 = {1, 4};
seg2 = {6, 3};

bat[s1_, s2_] = s1 + s2;

batseg=bat[seg1, 
        seg2]

Show[
        Graphics[{Arrow[{0, 0}, seg1], 
            Arrow[{0, 0}, seg2], 
{Hue[0.3], 
              Thickness[0.008], 
              Arrow[{0, 0}, batseg]}, 
{Hue[0.7], 
              Thickness[0.005], 
              Dashing[{0.02, 0.02}], 
Line[{seg1, batseg}], 
              Line[{seg2, batseg}]}, 
Text[seg1, 
              seg1, {0, -1}, {1, 0}], 
            Text[seg2, seg2, {0, -1}, {1, 0}], 
Text[
              batseg, batseg, {0, -1}, {1, 
                0}]}], 
Axes -> True, 
        PlotRange -> All];

angelua[s1_, s2_] := 
        N[ArcCos[s1 . s2/(luzera[s1]*luzera[s2])]];

angelua[seg1, seg2]/Degree

area[s1_, s2_] := 
      luzera[s1]*luzera[s2]*Sin[angelua[s1, s2]];

area[seg1, seg2]

seg1a = seg1; AppendTo[seg1a, 0];
seg2a = seg2;AppendTo[seg2a, 
      0];

luzera[CrossProduct[seg1a, seg2a]]       (* 
      paralelogramoaren area bektoreen biderkadura bektorialaren bidez *)

Puntu batetik zuzen baterako distantzia (zuzena -> ax+by+c=0, puntua ->((Subscript[x, 0]), (Subscript[y, 0])), 
distantzia -> |a(Subscript[x, 0]) + (Subscript[by, 0]) + c|/(Sqrt[(a^2) + (b^2)]))

y[x_] = 1.5*x - 3;      (* 
      zuzena *) 
puntu = {3, -2};         (* hautazko puntua *)

ck = y[0];
bk = -1;
ak = (y[x] - ck)/x;

dist = 
      Abs[ak*puntu[[1]] + bk*puntu[[2]] + ck]/
        luzera[{ak, bk}]

segperpend = {ak, bk};
maldaperpend = bk/ak;
yperp[x_] = 
        puntu[[2]] + (x - puntu[[1]])*
            maldaperpend;
xperpend = ((ck - puntu[[2]]) + 
              puntu[[1]]*maldaperpend)/(maldaperpend - 
              ak);
yperpend = y[xperpend];
puntuperpen = {xperpend, yperpend};

yperp[x]

xmin = 
        Min[puntu[[1]] - 1, 
          puntuperpen[[1]] - 1];
xmax = 
        Max[puntu[[1]] + 1, 
          puntuperpen[[1]] + 1];
ymin = 
        Min[puntu[[2]] - 1, puntuperpen[[2]] - 1, y[xmin] - 1, 
          y[xmax] - 1];
ymax = 
        Max[puntu[[2]] + 1, puntuperpen[[2]] + 1, y[xmin] + 1, 
          y[xmax + 1]];
prop = (ymax - ymin)/(xmax - 
            xmin);

Show[{Plot[
            y[x], {x, -5, 
              5}, 
AxesOrigin -> {0, 0}, 
            DisplayFunction -> 
              Identity], 
Graphics[{{Hue[0.3], 
                Thickness[
                  0.01], 
Line[{puntu, 
                    puntuperpen}]}, {PointSize[0.02], Hue[0.1], 
                Point[puntu], 
Point[puntuperpen]}, 
              Text[N[puntu], 
                puntu, {0, -1}, {1, 0}], 
Text[
                N[puntuperpen], 
                puntuperpen, {0, -1}, {1, 
                  0}]}]}, 
Axes -> True, 
        PlotRange -> {{xmin, xmax}, {ymin, 
              ymax}}, 
DisplayFunction -> $DisplayFunction, AspectRatio -> prop];

Geometria 3D espazioan

Puntu bat eta bi segmentuetaz definitutako planoa

pt1 = {1, 3, 4};       
seg1 = {1, 0, 0.5};seg2 = {0.5, 
        2, -1};

MatrixForm[
      planomat = 
        Transpose[{seg1, seg2, {x, y, z} - pt1}]]

Det[Transpose[{seg1, seg2, {x, y, z} - pt1}]]

Show[{ParametricPlot3D[
            pt1 + u*seg1 + v*seg2, {u, -2, 2}, {v, -2, 
              2}, 
DisplayFunction -> 
              Identity], 
Graphics3D[{{Hue[0.9], 
                Thickness[0.008], 
Line[{pt1, pt1 + seg1}], 
                Line[{pt1, pt1 + seg2}]}, 
{PointSize[
                  0.04], Hue[0.8], 
                Point[pt1]}}]}, 
DisplayFunction -> $DisplayFunction, 
Axes -> True, 
        PlotRange -> All, AxesLabel -> {x, y, z}, 
        ViewPoint -> {1.702,  2.955,  1.928}];