使用Graphics3D在XYZ坐标系上绘制球体

K7PEH 06/24/2018. 2 answers, 173 views
graphics3d

我认为应该有一个简单的方法来完成我的任务,但我还没有找到它。 我希望Graphics3D绘制一个简单的球体,半径$ 1 $,以$ {0,0,0} $为中心。 并且,绘图应该没有框(易于操作),但坐标轴以球体本身为中心。 使用Graphics3D,这些坐标轴位于球体之外,就好像它们标记了边界框的3个边缘一样。

应该可以看到球体表面有点透明,可以看到球体内的轴。

我想指导如何解决这个问题,认为必须有一个共同的需求,必须有一个我尚未找到的简单参数。 我确信我可以通过绘制每个轴手动构建这样的3D图像,但我希望避免这种情况。

我承认自己是Mathematica图形的新手,尤其是Graphics3D。

2 Answers


rhermans 06/25/2018.

Graphics3D

Graphics3D[
 {Opacity[0.5], Sphere[{0, 0, 0}]}
 , AxesOrigin -> {0, 0, 0}
 , Boxed -> False
 , Axes -> True
 , PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}
 ] 

Mathematica图形

如何解决这个问题。

一个很好的起点是查看有关Graphics3D文档 ,搜索此站点,并查看相关功能的选项

Options[Graphics3D]
(* {AlignmentPoint -> Center, AspectRatio -> Automatic, 
 AutomaticImageSize -> False, Axes -> False, AxesEdge -> Automatic, 
 AxesLabel -> None, AxesOrigin -> Automatic, AxesStyle -> {}, 
 Background -> None, BaselinePosition -> Automatic, BaseStyle -> {}, 
 Boxed -> True, BoxRatios -> Automatic, BoxStyle -> {}, 
 ClipPlanes -> None, ClipPlanesStyle -> Automatic, 
 ColorOutput -> Automatic, ContentSelectable -> Automatic, 
 ControllerLinking -> Automatic, ControllerMethod -> Automatic, 
 ControllerPath -> Automatic, CoordinatesToolOptions -> Automatic, 
 DisplayFunction :> $DisplayFunction, Epilog -> {}, FaceGrids -> None,
  FaceGridsStyle -> {}, FormatType :> TraditionalForm, 
 ImageMargins -> 0., ImagePadding -> All, ImageSize -> Automatic, 
 ImageSizeRaw -> Automatic, LabelStyle -> {}, Lighting -> Automatic, 
 Method -> Automatic, PlotLabel -> None, PlotRange -> All, 
 PlotRangePadding -> Automatic, PlotRegion -> Automatic, 
 PreserveImageOptions -> Automatic, Prolog -> {}, 
 RotationAction -> "Fit", SphericalRegion -> False, 
 Ticks -> Automatic, TicksStyle -> {}, TouchscreenAutoZoom -> False, 
 ViewAngle -> Automatic, ViewCenter -> Automatic, 
 ViewMatrix -> Automatic, ViewPoint -> {1.3, -2.4, 2.}, 
 ViewProjection -> Automatic, ViewRange -> All, 
 ViewVector -> Automatic, ViewVertical -> {0, 0, 1}} *) 

Jens 06/25/2018.

即使答案已经被接受,让我发布我喜欢用3D制作轴的方法:

首先,定义一个名为arrowLine的通用3D箭头(与内置的Arrow命令相比,它允许更健壮的方式指定形状的比例)。 看到这个答案 。 然后我在函数arrowAxes组合了三个这样的箭头来制作一个坐标系:

Options[arrowLine] = {Thickness -> .1, "HeadScale" -> 3};
arrowLine[{p1_, p2_}, 
  OptionsPattern[]] :=
(*p1 and p2 are 3D points. They are passed as a list*)
 Module[{p3, scale2, norm, pyramidHeight = 3/2}, 
  scale2 = OptionValue["HeadScale"]*OptionValue[Thickness];
  norm = Norm[p2 - p1];
  If[norm > scale2*pyramidHeight, 
   p3 = p1 + (p2 - p1)/norm (norm - scale2 pyramidHeight);
   {EdgeForm[], Cylinder[{p1, p3}, OptionValue[Thickness]], 
    GeometricTransformation[
     GraphicsComplex[{{0, 0, pyramidHeight}, {0, -1, 0}, {0, 1, 
        0}, {-1, 0, 0}, {1, 0, 0}}, 
      Polygon[{{3, 4, 1}, {4, 2, 1}, {2, 5, 1}, {5, 3, 1}, {5, 2, 4, 
         3}}]], Composition[TranslationTransform[p3], 
      Quiet[RotationTransform[{{0, 0, 1}, 
         p2 - p1}], {RotationMatrix::degen, RotationTransform::spln}],
       ScalingTransform[scale2 {1, 1, 1}]]]}, {}]]   

arrowAxes[forwardLength_, backwardLength_: 0] := 
 Map[{Apply[RGBColor, #], 
    arrowLine[{-backwardLength #, forwardLength #}, 
     Thickness -> .05]} &, IdentityMatrix[3]] 

现在3D轴可以与部分半透明球体组合,如下所示:

Graphics3D[{{Opacity[.7], Orange, Sphere[]}, arrowAxes[3, 3]}, 
 Boxed -> False, Lighting -> "Neutral", Background -> Gray] 

Mathematica图形

半透明效果由Opacity创建,轴由arrowAxes[3, 3]绘制。 这里,第一个参数是从原点开始向前的箭头长度,第二个参数是反向的长度。 您可以省略第二个参数以获得仅在向前方向上延伸的轴(与第一个八分圆相邻)。


HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
2 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
3 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
4 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
5 Eminem

Venom flac

Eminem. 2018. Writer: Eminem.
6 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
7 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
8 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
9 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
10 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
11 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
12 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
13 Lukas Graham

Love Someone flac

Lukas Graham. 2018. Writer: Don Stefano;Morten "Rissi" Ristorp;Morten "Pilo" Pilegaard;Jaramye Daniels;James Alan;David LaBrel;Lukas Forchhammer Graham.
14 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.
15 Deep Chills

Run Free flac

Deep Chills. 2018.
16 Khalid

Better flac

Khalid. 2018. Writer: Charlie Handsome;Jamil Chammas;Denis Kosiak;Tor Erik Hermansen;Mikkel Stoleer Eriksen;Khalid.
17 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.
18 NCT 127

Regular (English Version) flac

NCT 127. 2018.
19 Camila Cabello

Consequences (Orchestra) flac

Camila Cabello. 2018. Writer: Emily Lynn Weisband;Nicolle Galyon;Amy Wadge;Bart Schoudel;Frank Dukes;Camila Cabello.
20 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.

Related questions

Hot questions

Language

Popular Tags