I have a code to replace the z coordinate of one point A(x,y,0) on the xy plane:
g[x_, y_, z_] := Piecewise[{{(x - 1/2)^2 + y^2 + z^2 - 1/16, (x - 1/2)^2 + y^2 - 1/16 <= 0 && z >= 0}}, z];
center = {0, 0, 1}; (* point O*)
a = {0.76, 0, 0}; (* one point A on xy plane*)
line = Line[{a, center}]; (* connecting line of OA *)
surface = ImplicitRegion[g[x, y, z] == 0, {x, y, z}]; (* A surface described by g[x,y,z] *)
(* intersection points of OA and the surface, there maybe more than one intersection points*)
intersection = MeshCoordinates@DiscretizeRegion@RegionIntersection[line, surface]
(*{{0.76, 0., 0.}, {0.579987, 0., 0.236859}, {0.749627, 0., 0.0136485}}*)
(* find the nearest intersection point to O *)
interPoint = Nearest[intersection, center][[1]]
(* {0.579987, 0., 0.236859}*)
(* calculate the distance between O and the nearest intersection point*)
d = EuclideanDistance[center, point]
(* 0.958525*)
(*produce a coordinate with replacing a[[3]] with d *)
data = {a[[1]], a[[2]], d}
(* {0.76, 0, 0.958525}*)
Then I want to do the same calculation for 100 (for example) points on xoy plane between -1<=x<=1 and -1<=y<=1, like (-1,0,0),(-0.9,0,0),...(-1,0.1,0),(-1,0.2,0)...... Then I can have a group of coordinats like (a[1],a[2],d).
For loop in other programming languages can do this. In Mathematica, it seems that I should use Table
to achieve it, but I am not familiar with Table
. Is there anybody can help me to finish this code?
And then I want to make a contour plot, with x,y-coordinates as position and z-coordinate as color. Like this one:
data = Table[t[x,y], {y, -1, 1, 0.1}, {x, -1, 1, 0.1}];
plot = ListDensityPlot[data, DataRange -> {{-1, 1}, {-1, 1}}
And another contour plot lines look like this(This maybe need 100*100 points):