This may be a silly question, but I basically need to find the radius of a cube in MAya.
Or another explanation would be I need to find the absolute center point, to the axis of choice example Y, so it would find out the radius of the Y direction if specified, or the distance from the center point to the furthest X direction, this would be the "radius".
Would love the help!
By analogy in 2 dimensions - or think of this as the center slice of the sphere in the cube.
Related
Let's say I have list of points P0, P1, P2, P3 with coordinates X,Y,Z
Then I have a list of points with coordinates X1, Y1, Z1
I had to find all points inside a certain radius around P0: I did this using python scipy library using kdtree and query_ball_point function.
But now I'd like to find all points inside a cube. Points (P0 and P1) are not centered in the rectangle.
(Z)height of the rectangle is Z+4.
(Y)The left side of P0 is +2 and right side of P0 is +1.
To get X we need to calculate the distance between P0 and P1...
Any ideas?
I have good programming knowledge but my math and geometry skills are lacking.
all you need to do is check all distnace conditions for every point in relation to your rectangle - in all dimensions x,y,z.
Lets say you have center of rectangle with coordinates cx,cy,cz
and you know that distance from X side is dX, from Y side is dY and from Z side is dZ.
the coordinates of your socalled center is cx,cy,cz
you can make loop
for point in all_points:
px,py,pz = point # coordinates of a point which you try to examine
if abs(cx-point[x]) < dX:
if abs(cy-point[y]) < dY:
if abs(cz-point[z]) < dZ:
print('point is inside so called cube')
#abs(cx-point[x]) equals distance between your center and examined point in x-axis dimension...
#dX is distance between cube side and cx (center of cube in x-axis)
NOTE:
This example is good for cube with center in the middle. Since your center is not really in the middle, I advice you to find the center and do the above example
If you cant calculate center of your cube, you cant solve this problem anyway, so you better find the center.
I'm currently working on a project about 3D rendering, and I'm trying to make simplistic program that can display a simple 3D room (static shading, no player movement, only rotation) with pygame
So far I've worked through the theory:
Start with a list of coordinates for the X and Z of each "Node"
Nodes are kept in an order which forms a closed loop, so that a pair of nodes will form either side of a wall
The height of the wall is determined when it is rendered, being relative to distance from the camera
Walls are rendered using painter's algorithm, so closer objects are drawn on top of further ones
For shading "fake contrast", which brightens/darkens walls based on the gradient between it's two nodes
While it seems simple enough, the process behind translating the 3D coordinates into 2D points on the screen is proving the difficult for me to understand.
Googling this topic has so far only yeilded these equations:
screenX = (worldX/worldZ)
screenY = (worldY/worldZ)
Which seem flawed to me, as you would get a divide by zero error if any Z coordinate is 0.
So if anyone could help explain this, I'd be really greatful.
Well the
screenX = (worldX/worldZ)
screenY = (worldY/worldZ)
is not the whole stuff that is just the perspective division by z and it is not meant for DOOM or Wolfenstein techniques.
Well in Doom there is only single angle of viewing (you can turn left/right but cannot look up/down only duck or jump which is not the same). So we need to know our player position and direction px,py,pz,pangle. The z is needed only if you want to implement also z axis movement/looking...
If you are looking in a straight line (Red) all the object that cross that line in the 3D are projected to single x coordinate in the player screen...
So if we are looking at some direction (red) any object/point crossing/touching this red line will be place at the center of screen (in x axis). What is left from it will be rendered on the left and similarly whats on right will be rendered on the right too...
With perspective we need to define how large viewing angle we got...
This limits our view so any point touches the green line will be projected on the edge of view (in x axis). From this we can compute screen x coordinate sx of any point (x,y,z) directly:
// angle of point relative to player direction
sx = point_ang - pangle;
if (sx<-M_PI) sx+=2.0*M_PI;
if (sx>+M_PI) sx-=2.0*M_PI;
// scale to pixels
sx = screen_size_x/2 + sx*screen_size_x/FOVx
where screen_size_x is resolution of our view area and point ang is angle of point x,y,z relative to origin px,py,pz. You can compute it like this:
point_ang = atan2(y-py,x-px)
but if you truly do a DOOM ray-casting then you already got this angle.
Now we need to compute the screen y coordinate sy which is dependent on the distance from player and wall size. We can exploit triangle similarity.
so:
sy = screen_size_y/2 (+/-) wall_height*focal_length/distance
Where focal length is the distance at which wall with 100% height will cover exactly the whole screen in y axis. As you can see we dividing by distance which might be zero. Such state must be avoided so you need to make sure your rays will be evaluated at the next cell if standing directly on cell boundary. Also we need to select the focal length so square wall will be projected as square.
Here a piece of code from mine Doom engine (putted all together):
double divide(double x,double y)
{
if ((y>=-1e-30)&&(y<=+1e-30)) return 0.0;
return x/y;
}
bool Doom3D::cell2screen(int &sx,int &sy,double x,double y,double z)
{
double a,l;
// x,y relative to player
x-=plrx;
y-=plry;
// convert z from [cell] to units
z*=_Doom3D_cell_size;
// angle -> sx
a=atan2(y,x)-plra;
if (a<-pi) a+=pi2;
if (a>+pi) a-=pi2;
sx=double(sxs2)*(1.0+(2.0*a/view_ang));
// perpendicular distance -> sy
l=sqrt((x*x)+(y*y))*cos(a);
sy=sys2+divide((double(plrz+_Doom3D_cell_size)-z-z)*wall,l);
// in front of player?
return (fabs(a)<=0.5*pi);
}
where:
_Doom3D_cell_size=100; // [units] cell cube size
view_ang=60.0*deg; // FOVx
focus=0.25; // [cells] view focal length (uncorrected)
wall=double(sxs)*(1.25+(0.288*a)+(2.04*a*a))*focus/double(_Doom3D_cell_size); // [px] projected wall size ratio size = height*wall/distance
sxs,sys = screen resolution
sxs2,sys2 = screen half resolution
pi=M_PI, pi2=2.0*M_PI
Do not forget to use perpendicular distances (multiplied by cos(a) as I did) otherwise serious fish-eye effect will occur. For more info see:
Ray Casting with different height size
I am trying to do this but in 3d and using a 2d circle instead of a box.
I have a line starting between the two points [ (0,0,0), (3,4,5) ] and I want to see if it intersects through
circle = Circle((2, 1), 0.5)
ax.add_patch(circle)
art3d.pathpatch_2d_to_3d(circle, z=1, zdir="x")
Is it possible to test for a path intersect on a 2d object plotted on 3d axis? From the linked example above, I want to do path.intersects_circle where I define a circle as:
I have had a look through the Bbox documentation and it seems that I can't use this method for a circle?
This sounds more like an algebraic problem than related to matplotlib.
This is how I understand your question:
you have a circle at (x=2,y=1) with a radius of r=0.5
this circle is located in a plane at a constant z=1
1.) You need to determine where your vector pierces the plane which is parallel to the x,y-plane and at z=1. For the vector you specify in your question this intersection is at:
x = 3./(2.**0.5)
y = 4./(2.**0.5)
z = 1.
2.) You need to determine if this intersection falls into the part of the plane covered by the circle. The maximum y-coordinate your circle reaches is 1.5 - the y-coordinate of the intersection is already larger. Hence your straight line does not pierce the circle.
All this being said, I would recommend implementing an algebraic check based on the intersection with the plane and determining if this intersection is part of the circle. And only then using matplotlib.
I need a way to characterize the size of sets of 2-D points, so I can determine whether to render them as individual points in a space or as representative polygons, dependent on the scale of the viewport. I already have an algorithm to calculate the convex hull of the set to produce the representative polygon, but I need a way to characterize its size. One obvious measure is the maximum distance between points on the convex hull, which is the diameter of the set. But I'm really more interested in the size of its cross-section perpendicular to its diameter, to figure out how narrow the bounding polygon is. Is there a simple way to do this, given the sorted list of vertices and and the indices of the furthest points (ideally in Python)?
Or alternatively, is there an easy way to calculate the radii of the minimal area bounding ellipse of a set of points? I have seen some approaches to this problem, but nothing that I can readily convert to Python, so I'm really looking for something that's turnkey.
You can compute:
the size of its cross-section perpendicular to its diameter
with the following steps:
Find the convex hull
Find the two points a and b which are furthest apart
Find the direction vector d = (a - b).normalized() between those two
Rotate your axes so that this direction vector lies horizontal, using the matrix:
[ d.x, d.y]
[-d.y, d.x]
Find the minimum and maximum y value of points in this new coordinate system. The difference is your "width"
Note that this is not a particularly good definition of "width" - a better one is:
The minimal perpendicular distance between two distinct parallel lines each having at least one point in common with the polygon's boundary but none with the polygon's interior
Another useful definition of size might be twice the average distance between points on the hull and the center
center = sum(convexhullpoints) / len(convexhullpoints)
size = 2 * sum(abs(p - center) for p in convexhullpoints) / len(convexhullpoints)
This is my homework question:
Expand on your Circle class by adding a method called exactly dist() which takes the x and y values of a point, and returns the distance of the point in coordinate space from the outside of the circle (or zero if the point is on or inside the circle).
The following code:
myCircle = Circle(1,1,1)
print myCircle.dist(3,4)
Should print an output of approximately:
2.6055512754639891
However I cant understand the question. What does it mean to return the point in coordinate space from the outside of the circle? Can you please explain it?
Find the distance between the center of the circle and the given point. Subtract the radius from the distance. Negative values are inside the circle.
You can easily check if the point is inside the circle on not. Once you've done that, and determined it is outside, you need to find a line normal to the circle and passing through the point. The length of the line from the circumference of the circle gives you the answer.
Hint: Any line passing through the center of the circle is normal to it.
So you have the point (x,y), radius r and center (x0,y0). I think you have enough information here to solve the problem :)
It probably means the distance to the closest point on the circle, so its a min-max problem wherre you are minimizing the distance of the point to circumfurance
>>> from math import hypot
>>> hypot(3-1,4-1) # How far is the point from the centre of the circle?
3.6055512754639891
>>> hypot(3-1,4-1)-1 # Now subtract the radius
2.6055512754639891
>>>