IsItSharp

Members
  • Content count

    83
  • Joined

  • Last visited

Community Reputation

369 Neutral

About IsItSharp

  • Rank
    Member
  1. I implemented a new class called "Sampler" which generates either random values, halton (2,3) values or sobol values and stores them before in an array before rendering. I tried every one and compared the results at 10 samples, and i am kind of disappointed by halton and sobol, they both look horrible, why is that?   This is my computeSamples(x,y)-function: def computeSample(x,y): samplePoint = sampler.getSamplePoint(x,y) jitterX = samplePoint[0] jitterY = samplePoint[1] x += jitterX y += jitterY xdir = (x / width) * 2.0 - 1.0 ydir = ((y / height) * 2.0 - 1.0) * aspect direction = Point3D(xdir,ydir,zdir).normalize() ray = Ray(camera,direction) return trace(ray,1) And this is my "Sampler": class Sampler: def __init__(self,type,width,height): self.type = type self.width = width self.height = height self.samplePoints = [] self.counter = 0 for x in range(width): for y in range(height): if(self.type is SampleType.Random): self.samplePoints.append([random(),random()]) elif(self.type is SampleType.Halton): self.samplePoints.append([Halton(2,self.counter),Halton(3,self.counter)]) elif(self.type is SampleType.Sobol): sobolValue = i4_sobol(2,self.counter) self.samplePoints.append([sobolValue[0][0],sobolValue[0][1]]) elif(self.type is SampleType.NoneS): self.samplePoints.append([0,0]) self.counter += 1 def getSamplePoint(self,x,y): return self.samplePoints[x*self.height+y]
  2. Thanks the floor function fixed it. I am wondering how i could use the halton sequence to sample a pixel? Would it be better to store the precalculated values in an array and choose the value according to the current samples / pixel? For example if i am in the 2nd sample i would choose the 2nd value of the 2- and 3-base halton series?
  3. I try to implement the Halton sequence with this simple code: def Halton(base,ix): r = 0 f = 1.0 / base i = ix while(i > 0): r += f * (i%base) f /= base i /= base return r i thought the output values are limited to [0..1] but sometimes i get values like "1.01953125" or "1.1861979166666667", why is that and how can i limit the Halton sequence to the given interval?
  4. Hi,   i would like to implement glass material in my pathtracer. I tried to copy the code from "PBR - From Theorie to Implementation" but i am not sure if i did it right. My current approach looks like this: The index of refraction outside glass is 1.0, inside it is 1.3. First i convert the direction vector to an angle called "cosThetaI": def getAngle(direction,normal): dotPr = direction.dot(normal) angle = math.acos(dotPr / (direction.length() * normal.length())) return angle If cosThetaI is greater than 0, i switch the refractive indices. etaI = 1.0 etaT = 1.3 cosThetaI = Point3D.getAngle(ray.direction,normal) cosThetaI = Point3D.clamp(cosThetaI,-1,1) if(cosThetaI > 0.0): etaI = 1.3 etaT = 1.0 cosThetaT = Point3D.snellsLaw(cosThetaI,etaI,etaT) Rparl = ((etaT * cosThetaI) - (etaI * cosThetaT)) / ((etaT * cosThetaI) + (etaI * cosThetaT)) Rperp = ((etaI * cosThetaI) - (etaT * cosThetaT)) / ((etaI * cosThetaI) + (etaT * cosThetaT)) dir = Point3D.getPoint((Rparl * Rparl + Rperp * Rperp) / 2) reflectionRay = Ray(hitPoint,dir.normalize()) def getPoint(angle): return Point3D(math.cos(angle),math.sin(angle),1) def snellsLaw(cosThetaI,etaI,etaT): sinThetaI = math.sqrt(max(0,1-cosThetaI*cosThetaI)) sinThetaT = etaI / etaT * sinThetaI cosThetaT = math.sqrt(max(0,1-sinThetaT * sinThetaT)) return cosThetaT I am not quite sure how to convert an angle into an 3D vector though...
  5. Hi, i am currently doing ray-circle intersection and i want to reflect the ray off a circle with a random vector if they intersect. This is the picture I have in my mind:     The orange point is the intersection point, the blue line is the normal from the center of the circle to the intersection point, the red dots are possible random points, how could i accomplish this?
  6. Thanks for your reply, do you mean like this? var normal = circ.pos.sub(cir.pos).normalize();   Where circ and cir are two circles which intersect each other.
  7.   Each circle changes its velocity vector so that they don't intersect each other anymore.
  8. Hi, i would like to calculate the reflection vector if two circles intersect each other. A circle is an object with radius, [x,y] and velocity vector [x_v,y_v]. How could i do that? In this case I don't have a normal vector like in the case of a line / circle intersection, have I?
  9. Check whether a Point lies in a line segment

    Thanks for the rectangle-hint! I did it like this and i think it is working now: Line.prototype.isOnLine = function (pos) { var lowerXBound = Math.min(this.start.x, this.end.x); var upperXBound = Math.max(this.start.x, this.end.x); var lowerYBound = Math.min(this.start.y, this.end.y); var upperYBound = Math.max(this.start.y, this.end.y); return pos.x >= lowerXBound && pos.x <= upperXBound && pos.y >= lowerYBound && pos.y <= upperYBound; } Have a nice day!
  10. Hi,   i would like to know how to check as simple as possible if a point lies on a line segment (which is finite). My line has a start (x_s,y_s) and end (x_e,y_e) point and i want to check if point (x_p,y_p) is on the line, how do i do that? The only source code i found does only check if the point is on the line but not on the segment...Any help is very much appreciated.
  11. Hi,   i am currently trying to calculate the incenter of a triangle. I read about this here: http://www.mathopenref.com/triangleincircle.html   My current problem is to calculate the angle bisectors. My triangle consists of three vertices (x and y coordinate). My current approach looks like this: Point v1 = listOfVertices[0]; Point v2 = listOfVertices[1]; Point v3 = listOfVertices[2]; double a = getLengthOfLine(new Line(v1, v2)); double b = getLengthOfLine(new Line(v2, v3)); double c = getLengthOfLine(new Line(v3, v1)); double angle = Math.Acos((a * a - b * b - c * c) / (-2.0 * b * c)) / 2.0; double slope = Math.Tan(angle); double yPart = v2.Y - slope * v2.X; Line bisecLine1 = new Line(v2, new Point(v2.X + 100, (int)((v2.X + 100) * slope + yPart))); double angle2 = Math.Acos((b * b - a * a - c * c) / (-2.0 * a * c)) / 2.0; double slope2 = Math.Tan(angle2); double yPart2 = v1.Y - slope2 * v1.X; Line bisecLine2 = new Line(v1, new Point(v1.X - 100, (int)((v1.X - 100) * slope + yPart))); But as soon as i change my vertice order from this: listOfVertices = new List<Point>() { new Point(200,100), new Point(25,75), new Point(75,200) }; to something else, my code doesn't work anymore (e.g. produces some weird lines), this is what i get with the code above (works as expected i think):     How can i determine, which side is a,b,c and which vertex belongs to which side?   Edit: Looks like i have some other problems in my bisector code too :(
  12. Hi,   because i love the idea of pathtracing i would like to port a simple 3D pathtracer (at first only with spheres) to a microcontroller. Because microcontrollers don't have a lot of RAM (usually) i have to figure out, how much i would actually need. I have a TFT-Display with 128x128 pixels. The last time i wrote a (very simple) pathtracer for a desktop-pc, i used a byte-array with 3 bytes (red, green blue) for every pixel. To do this on a microcontroller this would lead to a total ram consumption of at least ~50kB! Do you have any ideas how i could shrink that memory consumption by saving data more efficiently?
  13. Thanks a lot for the hint. I googled a bit and came up with this code:   def arrange(): global index if(index == len(rList)): return 0 rect = rList[index] for i in range(0,len(freeNodesList)): node = freeNodesList[i] if(node.width >= rect.width and node.height >= rect.height): #rectangle fits inside the node freeNodesList.pop(i) #remove current node because it's going to be filled rect.sX = node.sX rect.sY = node.sY node.rectangle = rect node.width = rect.width node.height = rect.height child1 = Node(wW-(node.sX+node.width),node.height,node.sX+node.width,node.sY) freeNodesList.append(child1) if(wH-(node.sY+node.height) > 0): #there is still space left to the top child2 = Node(wW,wH-(node.sY+node.height),0,node.sY+node.height) freeNodesList.append(child2) index += 1 break; else: #current node doesn't fit continue But it is not working as expected. The problem is, that i generate two new nodes after every rectangle and that those nodes don't consider the already placed rectangles. I made a short gif which should show that problem:   So basically i have to check for every node if there is already a rectangle which shrinks the originally intended space. The next problem would be to combine two free nodes if there is a rectangle which can only be placed if those two nodes are combined. I would really appreciate it if someone could explain to me how i can solve those problems. Best regards
  14. Hi,   i am wondering how i could arrange 2D areas with given width and height in the most effective way (no overlapping) on a surface (also with a given width and height)? I have literally no clue where and how i should start. I visualized my intentions with a small image.
  15. Horizontal throw with air resistance

    What happens if you use 0.01 for your ballMass?