# Tag Info

## New answers tagged computational-geometry

3

I stopped debugging after the first line. The problem is you need p1 : {x1_, x2_} and you have p1_ : {x1_, x2_} where {x1_, x2_} is Optional for missing entry. Which makes xi_ not associated with an input at all, they will appear only when the input is missing. Unless you fix your code you can only use pi references. But the very outer statement is If ...

2

One can use FindMinimum[] with RegionDistance[rect] to get a quick, accurate result. Speed can be expected here because we have a good estimate for a starting value for s in the parameter T. Block[{T = 1.}, rect = Polygon[{{xr1, yr1}, {xr2, yr2}, {xr3, yr3}, {xr4, yr4}} /. {t -> T}]; df = RegionDistance[rect]; ndf[{x_Real, y_Real}, df_] := df[{x, y}]...

1

Something like this I think, You first extract your points from the curve, then define the polygon to be a function of the parameter T pts = Cases[ParametricPlot[{xc, yc}, {s, 0, 4},PlotPoints->300], Line[{x__}] :> x, Infinity]; pgon[T_] := Polygon[{{xr1, yr1}, {xr2, yr2}, {xr3, yr3}, {xr4, yr4}} /. {t -> T}] (edit I had to add a high ...

2

In this case, the intersection between two 2D regions is a 1D region - a line. It makes sense that the functions that are called by RegionMeasure and RegionIntersection might be influenced by roundoff errors associated with using floating point numbers rather than exact numbers. So a workaround is to convert your expressions to use exact numbers prior to ...

7

This is a MeshRegion, SeedRandom[420]; pts = RandomReal[{-1, 1}, {8, 2}]; mesh = VoronoiMesh[pts] You could get the individual polygons with MeshPrimitives and then use Area to find the area. This was my first thought, but the comments below made me realize it is much faster to use the built-in functions PropertyValue and MeshCellMeasure. So at the ...

4

For a closed surface such as this one, a slight modification of the function MakeTriangleMesh[] in this answer can be used: MakeTriangleMesh[vl_List, {closedu : (True | False) : False, closedv : (True | False) : False}, opts___] := Module[{dims = Most[Dimensions[vl]], v = vl, idx}, idx = Partition[Range[Times ...

2

This is not an answer but a comment on the speed issue @J.M. mentioned: One thing that can be done is to use Needs["NDSolveFEM"] bmesh = ToBoundaryMesh[r, {{-1.1, 1.1}, {-1.1, 1.1}, {-1., 1.}}, MaxCellMeasure -> {"Length" -> 0.1}]; (* bmesh = ToBoundaryMesh[dod] *) pts = bmesh["Coordinates"]; tri = Join @@ ElementIncidents[bmesh["...

6

It is confirmed as an improper behavior of RegionDifference by Wolfram support([CASE:3624735]). Here is their workaround: Instead of using boundary representation of geometric regions as given below, try using just the geometric regions in geometric computations. To be specific, here is the solution to this problem. Assuming wordRegion and disks ...

17

I guess I should not have been surprised that there are actually many ways to estimate the Gaussian and mean curvature of a triangular mesh. I shall present here a slightly compacted implementation of the MDSB method, with a few of my own wrinkles added in. I should say outright that the current implementation has two weaknesses: the determination of the ...

14

It took me a while, but the suggestion of @Michael E2 was quite helpful, and especially the post (Optimize inner loops). For those of you (like me) who are new to this style of programming in Mathematica there are a few things that helped in my particular example. In my slow version I was looping over all vertices in the mesh list. For example in ...

6

Here is another approach. Mathematica uses Triangle as it's 2D mesh generator. Triangle is very efficient and returns good results for numerical routines like the Finite Element Method or interpolation functions. However, to the best of my knowledge, there is not way to tell Triangle to use not generate triangles that have a angles that are larger than a ...

5

The following works reasonably well, up to a minimum area cutoff that is needed to limit the evaluation time: TriLengths[{a_, b_, c_}] := Module[{A, B, C}, A = Sqrt[(b - a).(b - a)]; B = Sqrt[(c - b).(c - b)]; C = Sqrt[(a - c).(a - c)]; {A, B, C}]; TriAngles[{a_, b_, c_}] := Module[{A, B, C, α, β, γ}, {A, B, C} = TriLengths[{a, b, c}]; ...

1

Something about your function TriAngles is interfering with MeshRefinementFunction. If I evaluate TriAngles inside the MeshRefinementFunction, then MeshRefinementFunction is ignored, even when the output of TriAngles isn't used. DiscretizeRegion[Disk[], MeshRefinementFunction -> Function[{vlist, area}, N@TriAngles[vlist]; If[area < 0.001, Return[...

4

This is just for fun. The square is found by finding the difference in lengths of adjacent sides of rectangle is zero. This exploits the symmetry in the y axis to find the square and does not address whether this is the only square set of points (i.e 'tilted' as referred to in comments). It is not particularly efficient. r[t_] := 2 - 2 Sin[t] + Sin[t] Sqrt[...

8

We can use symmetry and find such points that have the same $x$ coordinate and difference of their $y$ coordinates is twice the $x$ coordinate. We use FindRoot and help it with initial point which we choose as the maximum $x$ coordinate - maxXt. Then we need to mirror two points and draw lines between. r[t_] := 2 - 2 Sin[t] + Sin[t] Sqrt[Abs[Cos[t]]]/(Sin[t]...

Top 50 recent answers are included