Tag Info

New answers tagged

7

As KennyColnago has observed your equations seem to be off but there is another way of determining the incircle. I'd already typed it up with sources that may be helpful so let's post it, even if it's the same thing. {a, b, c} = {Norm[pC - pB], Norm[pA - pC], Norm[pA - pB]}; area = With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]; r = 2 area/(a + ...


10

version 10 pA = {0, 0}; pB = {1.1, 1}; pC = {1.5, 0}; lr = MeshRegion[{pA, pB, pC}, Triangle[Range@3]]; r1 = RegionDistance[InfiniteLine[{pA, pB}], {x, y}]; r2 = RegionDistance[InfiniteLine[{pB, pC}], {x, y}]; r3 = RegionDistance[InfiniteLine[{pC, pA}], {x, y}]; centerC = {x, y} /. NSolve[{r1 == r2, r2 == r3}, {x, y}, Reals]; centerC = Select[centerC, ...


7

The incircle of a triangle may be calculated as follows. InCircle[{x1_, y1_}, {x2_, y2_}, {x3_, y3_}] := With[{ a = Norm[{x2,y2} - {x3,y3}], b = Norm[{x3,y3} - {x1,y1}], c = Norm[{x1,y1} - {x2,y2}]}, Circle[(a {x1, y1} + b {x2, y2} + c {x3, y3})/(a + b + c), 1/2 Sqrt[-(((a - b - c) (a + b - c) (a - b + c))/(a + b + ...


0

A solution using ParametricPlot CirclePoints[r_, n_, o_: {0, 0}] := Module[{f = r {Sin[t], Cos[t]} + o, p}, p = f /. t -> # & /@ Range[0, 2 Pi, 2 Pi/n]; Show[ ParametricPlot[f, {t, 0, 2 Pi}], Graphics[{Red, PointSize[0.02], Point[p]}], Graphics[{Green, Line[p]}]]] CirclePoints[2, 6, {1, 0}]


0

One compact way to get $n$ points on a circle would be CirclePoints[center_,radius_,n_] := (center+radius #&) /@ Transpose @ Through[{Re,Im}[Exp[2\[Pi] I Range[n]/n]]]


2

Here is a quick and dirty (read approximate) way to achieve this using Version 10 capabilities: circ[ctr_, r_, n_] := MeshCoordinates @ DiscretizeRegion[Circle[ctr, r], MaxCellMeasure -> {"Length" -> 2 Pi r /(n - 1.5)}] Here ctr is the center, r, the radius and n number of points. Visualize (for $n = 5$): ...


4

Here is another way to get points equally spaced by chord-length. It will give a good result if the chord length is relatively small compared to the maximum radius of curvature along the curve. (If, say, the chord length is no greater than the maximum radius, then between successive points, the turning will be less 60 deg., and the difference between the ...


4

Walking infinitely in a random and acceptable direction within a rectangle on button click, stepSize = 1. DynamicModule[{newDir, walk = {{0, 0}}, oldPos, newPos = {0, 0}, acceptQ = -20 <= #[[1]] <= +20 && -10 <= #[[2]] <= +10 &}, { Button["Next Step", oldPos = newPos; newPos = {\[Infinity], \[Infinity]}; ...


24

To answer your question: I don't think it's a bad or good idea to use If. It depends on how you do it. To demonstrate I'll use If combined very powerfully with Mathematica 10's ability to tell if a point is inside a specified region or not. step[position_, region_] := Module[{randomStep}, randomStep = RandomChoice[{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}]; ...


6

I chose the WienerProcess as the underlying random process, as this will simulate a Brownian motion. Until Boundary Hit Module[{rd = Transpose @ RandomFunction[WienerProcess[], {0, 1000, .01}, 2]["States"], length}, length = LengthWhile[rd, # ∈ Rectangle[{-2, -2}, {+2, +2}] &]; ListPlot[rd[[;; length]], Joined -> True, Mesh -> All, PlotRange ...


13

I suggest using Mod - a natural thing for looped boundary conditions on a torus. Finite torus surface area is your bounded region. 2D random walk generally is simple: walk = Accumulate[RandomReal[{-.1, .1}, {100, 2}]]; Graphics[Line[walk], Frame -> True] Confinement to square region {{0,1},{0,1}} would be simple in principle with Mod[walk,1] ...


7

Here's my implement of a random walk within a circle using If and FoldList. Please see @Pickett's answer for more thorough implementation for arbitrary regions. Code updated to flesh out behavior near edge of region (if a step becomes out of bound, the current position will randomly look for the other step types that would stay in the region). I also added ...


4

ImplicitRegion (and ParametricRegion) represent a region. They are not for plotting. Thus RegionPlot is not even remotely an alternative. You can do many operations on regions that you can look up in the documentation centre. Just a few examples: you can compute their size, decide if a point is within, compute the distance between them, find their ...


4

Mathematica 10 provides new functionality dealing with curves, (see e.g. the Vector Analysis tutorial) like ArcLength, ArcCurvature and especially FrenetSerretSystem: FrenetSerretSystem[{ x1, ..., xn}, t] gives the generalized curvatures and Frenet-Serret basis for the parametric curve x[t] i.e. it returns {{ k1, ..., k(n-1)}, { e1, ..., en}}, where ki ...


14

The kite-domino tiling is based the pinwheel tiling which is falls out of a particular decomposition of a right triangle with legs of length 1 and 2. In the code that follows, rt[{a,b,c}] represents such a right triangle and dissect indicates how such a triangle should be decomposed into smaller copies of itself. We simply iterate the dissect function on ...



Top 50 recent answers are included