简体   繁体   English

VPython绘图半球

[英]Vpython drawing hemisphere

I have a sphere plotted on my program as so: 我在程序上绘制了一个球体,如下所示:

ball=sphere(pos=vector(0,0,0),opacity = 0.5,radius=0.95,color=color.black)

Is there any way of making it only show the top half of the sphere? 有什么办法让它只显示球体的上半部分吗?

I'm using vpython. 我正在使用vpython。

Thank you, 谢谢,

The best way to do this is make an extrusion. 最好的方法是进行挤压。 Make your shape a quarter of a circle, then arc the extrusion in a whole 60 degrees. 使形状为四分之一圆,然后在整个60度弧上弯曲拉伸。 If you see the extrusion examples they have a lot of help about this and so does the documentary of vpython. 如果您看到了挤出示例,那么他们在此方面有很多帮助,vpython的纪录片也有很多帮助。

ex: 例如:

    circle = shapes.circle(radius=20) #you can use the size of your choice
    square1 = Polygon[(-10,-20),(-10,20),(0,20),(0,-20)]
    square2 = Polygon[(0,0),(0,20),(20,20),(20,0)]

    rotation = paths.arc(radius=20, angle2=pi)

    Hemisphere = extrusion(pos=rotation,shape=circle-square1-square2)

not sure if this is fully syntax error free, etc. but I think you understand the idea behind this. 不知道这是否完全没有语法错误,等等。但是我认为您了解这背后的想法。 The quarter of a circle get rotated from the centre until it make a complete hemisphere. 四分之一圆从中心开始旋转,直到形成完整的半球。 Hope you get the idea, just did this but for making a full sphere with a chuck taken out as if a slice of cake was out of the sphere. 希望您能想到这个,只是这样做了,但是要做成一个完整的球体,然后拿出一个卡盘,好像一块蛋糕不在球体中一样。

您可以制作一个黑色的盒子,使其覆盖一半的球面,但除此之外,我不知道对不起

just to be clear i have done this using extrusions, only i needed a 3/4 of a sphere. 为了清楚起见,我已经使用拉伸完成了此操作,仅我需要一个3/4的球体。 Make a half cirlce shape by calling circle then subtract a square on half the circle. 通过调用圆来制作半圆形,然后在圆的一半上减去一个正方形。 After this make your rotation equal to 1pi (half a circle) here is how to do it: 在此之后,使您的旋转等于1pi(半圈),这里是如何做的:

    S1 = shapes.circle(radius=1)

    angle = 180 #degrees
    angle = angle=angle*(pi/180) #convert to radians (1pi)

    sq = Polygon([(-10,-20),(-10,20),(0,20),(0,-20)])
    semicircle = paths.arc(radius=0.000000001, angle1=pi/2, angle2=2.2*pi)

    mf = frame()
    Layer20_Extrusion = extrusion(frame=mf,pos=semicircle, shape=S1-sq,color=wh)

    mf.rotate(angle=angle)
    mf.pos=(0,0,0)

you will have to rotate it so that its the top half missing instead of the side, 您将不得不旋转它,以便其上半部而不是侧面丢失,

haven't used this code in a while so i am not sure why the radius = 0.0000000001 ish but i think you should be able to figure out what i did, sorry for the late response with code, when you posted this question i was trying to solve the same issue. 一段时间未使用此代码,所以我不确定为什么radius = 0.0000000001 ish,但我认为您应该能够弄清楚我的所作所为,对于代码的最新答复,当您发布此问题时,我正在尝试解决相同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM