New answers tagged

2

Using ClipPlanes and ClipPlanesStyle Animate[Graphics3D[Cuboid[{2, -2, -1}, {-2, 2, 3}], ClipPlanes -> -{-t, -t, 1, 0}, Boxed -> False, ClipPlanesStyle -> Directive[Yellow, Opacity[0.5], Specularity[White, 30]] ], {{t, -0}, -3, 3}, AnimationRunning -> False]


0

One big obstacle with your data is that it can't be defined as a single-valued function of x - it curves backward at the end. If I take your data and define it as pts, then we can see what we are going for here Show[ RegionPlot[ ImplicitRegion[ Sqrt[x^2 + y^2] == 0.99, {{x, 0.01, 0.99}, {y, 0.01, 0.99}}]], Graphics@Line@pts] The trick I'll use ...


1

Rainer showed that we can use our calculus skills to set up the proper integral and evaluate it analytically. But we can also solve this problem using the Region functionality in Mathematica to solve the problem. Let's take an arbitrary ellipse and a couple of points, as stated in the OP ellipse = TransformedRegion[ Ellipsoid[{14, 14}, {5, 2}], ...


3

user21 says it isn't guaranteed that the vertices will be in counter-clockwise order, but I can't find a counter-example. Using the method described here we can make a little function that tests a polygon for whether its vertices are CCW ccwQ[list_List] := Positive@Total[Subtract @@@ (list RotateLeft[Reverse /@ list])] ccwQ[poly_Polygon] := ...


3

Here is some code I have for making fake Voronoi diagrams, adapted to the Poincaré disk model. The result has the look and feel of having been drawn with a charcoal pencil, which may or may not be desired for your application. The strategy is adapted from suggestions by Worley and Schlick. (* some points *) BlockRandom[SeedRandom[42, Method -> ...


7

Solution for Update1 The ellipses described by matThetaList can be plotted by Show[ParametricPlot[#[[1]].{Sin[θ], Cos[θ], 1}, {θ, 0, 2 Pi}] & /@ matThetaList, PlotRange -> All] To describe each of these four curves as an ImplicitRegion, first eliminate θ from the parametric equations given in the question, h = Total[#^2 & /@ ({Sin[θ], ...


6

EDIT (incorporating comments by @J.M.: DistanceFunction->dis and pre-computation of nearest function): This is not efficient. Just rewriting metric (apologies for errors). In the following I used ContourPlot but DensityPlot could be used. dis[a_, b_] := Abs[ArcCosh[1 + 2 ( a - b).(a - b)/((1 - a.a) (1 - b.b))]] vh[n_] := Module[{p = ...


7

Here, I applied the discrete strategy(sampling $400$ points in a period $2\pi$) to calculate the boundary of ellipses $E_1,\cdots,E_n$. The algorithm mainly consists of four steps as follows : Using the ellipses $E_2,\cdots,E_n$ to trim the black segment of the first ellipse $E_1$; Using the ellipses $E_1,\cdots,E_{n-1}$ to trim the red segment of the last ...


9

It still feels a little bit wasteful for me to use a trigonometric function so there's room for improvement, but it's not as wasteful as bringing to bear region functionality on this problem: sameLine[InfiniteLine[{u1_, u2_}], InfiniteLine[{v1_, v2_}]] := With[{u = u1 - u2, v = v1 - v2}, PossibleZeroQ[VectorAngle[u, v]] || PossibleZeroQ[VectorAngle[u, v] ...


10

Here's another approach: DeleteDuplicates[lines, And @@ RegionMember[#, #2[[1]]] &] (* {InfiniteLine[{{0, 0}, {1, 0}}], InfiniteLine[{{0, 1}, {1, 0}}]} *)


13

DeleteDuplicates[lines, MemberQ[{##},RegionIntersection @ ##]&] {InfiniteLine[{{0, 0}, {1, 0}}], InfiniteLine[{{0, 1}, {1, 0}}]}


3

Here are two additional approaches, one uses RegionIntersection, the other uses DiscretizeGraphics: f[x_, y_, z_] = x^4 + y^4 + z^4 - 1; g[x_, y_, z_] = x - 2 y + z - 2; regF = ImplicitRegion[f[x, y, z] == 0, {x, y, z}]; regG = ImplicitRegion[g[x, y, z] == 0, {x, y, z}]; reg = DiscretizeRegion @ RegionIntersection[regF, regG] MeshCoordinates @ reg // ...


4

For version 9: f[x_, y_, z_] := x^3 + y^2 - z^2 g[x_, y_, z_] := x^2 + y^2 + z^2 - 1 cp3d = ContourPlot3D[{f[x, y, z]==0, g[x, y, z]==0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, BoundaryStyle -> {1 -> None, 2 -> None, {1, 2} -> {Thick, Red}}, ContourStyle -> Opacity[.7], Mesh -> None, ImageSize -> 400]; points = Cases[Normal@cp3d, ...


3

Finding the convex hull of points in $\Re^d$ and expressing it as a set of (in)equalities is hard. However, I would suggest you transform the problem by writing feasible points as convex combinations of the given points, i.e. $$x=\sum_{i=1}^{d} w(i)\, x(i)$$ and then optimize over the simplex $$\left\{ 0\leq w(i) \leq 1, \sum_{i=1}^{d} w(i) = 1\right\}$$ ...


7

For 2D, just find the Polygon representing the convex hull and use RegionMember: (* fake data *) rand = Round[RandomReal[{0, 1}, {10, 2}], 1/100]; prims = MeshPrimitives[ConvexHullMesh[rand], 2][[1, 1]]; Refine[RegionMember[Polygon[Round[prims, 1/100]], {x, y}], {x, y} ∈ Reals] 1/25 (1/20 - x) + 18/25 (-1/50 + y) >= 0 && -23/25 (-77/100 + ...


1

One way to treat this in some very special, low dimensional and friendly cases is to use ParametricRegion (*Dimension and number of points*) d = 5; np = 4; (*Generate data*) data = RandomInteger[{-10, 10}, {np, d}]; (*Convex hull*) ws = Array[w, Length[data]]; reg3 = ParametricRegion[ {Sum[ws[[i]]*data[[i]], {i, Length@data}], Total[ws] == 1} , ...


6

I'm not sure what kinds of calculations you'll want to do on the intersection line; but to get a sample of points on the intersection line, you could use DiscretizeRegion and MeshCoordinates: f[x_, y_, z_] = x^4 + y^4 + z^4 - 1; g[x_, y_, z_] = x - 2 y + z - 2; ContourPlot3D[{f[x, y, z] == 0, g[x, y, z] == 0}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, ...


2

As others mentioned, Qhull can do this. There are multiple ways to access Qhull from Mathematica. One way is through the mPower package, now part of xCellerator. An answer discussing how to install the package is here: http://mathematica.stackexchange.com/a/18909/12 Another way is the qh-math package, described in this answer: ...


3

Thanks @physicien for the comment on Quickull and Qhull, see his comment on the question. Sadly, I did not understand the paper and so I wanted to give this a shot in Mathematica with some very rude implementation (sorry, I am extremly bad at programming). There is a lot of room for improvement (my solution is extremly slow in high dimensions and for large ...



Top 50 recent answers are included